We're working on a platformer game and we need to be able to tweak the movement while the character is jumping. First we were using the standard CharacterController, but we couldn't change the jumping behaviour. So now, we have built a custom characterController, characterObject and bepuPhysicsWorld. These are currently all based on the standard code in the engine, that we got from the google repository.
We believe we have to change the HandleHorizontalMotion method of the CharacterController, but we don't fully understand what the function of supportLocationVelocity and the supportNormal are. If you could clarify this code a bit, it would help us out alot.
We think the solution lies in that code, but we're not entirely sure. If there is another (easier) way to change the jumping behaviour, please let us know.
- Código: Selecionar todos
/// Manages movement acceleration, deceleration, and sliding.
/// <param name="supportLocationVelocity">Velocity of the support point connected to the supportEntity.</param>
/// <param name="supportNormal">The normal at the surface where the ray hit the entity.</param>
/// <param name="dt">Timestep of the simulation.</param>
private void HandleHorizontalMotion(Vector3 supportLocationVelocity, Vector3 supportNormal, float dt)
if (HasTraction && MovementDirection != Vector2.Zero)
//Identify a coordinate system that uses the support normal as Y.
//X is the axis point along the left (negative) and right (positive) relative to the movement direction.
//Z points forward (positive) and backward (negative) in the movement direction modified to be parallel to the surface.
Vector3 x = Vector3.Cross(new Vector3(MovementDirection.X, 0, MovementDirection.Y), supportNormal);
Vector3 z = Vector3.Cross(supportNormal, x);
//Remove from the character a portion of velocity which pushes it horizontally off the desired movement track defined by the movementDirection.
float bodyXVelocity = Vector3.Dot(Body.LinearVelocity, x);
float supportEntityXVelocity = Vector3.Dot(supportLocationVelocity, x);
float velocityChange = MathHelper.Clamp(bodyXVelocity - supportEntityXVelocity, -dt * TractionDeceleration, dt * TractionDeceleration);
Body.LinearVelocity -= velocityChange * x;
float bodyZVelocity = Vector3.Dot(Body.LinearVelocity, z);
float supportEntityZVelocity = Vector3.Dot(supportLocationVelocity, z);
float netZVelocity = bodyZVelocity - supportEntityZVelocity;
//The velocity difference along the Z axis should accelerate/decelerate to match the goal velocity (max speed).
if (netZVelocity > MaxSpeed)
velocityChange = Math.Min(dt * TractionDeceleration, netZVelocity - MaxSpeed);
Body.LinearVelocity -= velocityChange * z;
velocityChange = Math.Min(dt * Acceleration, MaxSpeed - netZVelocity);
Body.LinearVelocity += velocityChange * z;
deceleration = dt * TractionDeceleration;
deceleration = dt * SlidingDeceleration;
//Remove from the character a portion of velocity defined by the deceleration.
Vector3 bodyHorizontalVelocity = Body.LinearVelocity - Vector3.Dot(Body.LinearVelocity, supportNormal) * supportNormal;
Vector3 supportHorizontalVelocity = supportLocationVelocity - Vector3.Dot(supportLocationVelocity, supportNormal) * supportNormal;
Vector3 relativeVelocity = bodyHorizontalVelocity - supportHorizontalVelocity;
float speed = relativeVelocity.Length();
if (speed > 0)
Vector3 horizontalDirection = relativeVelocity / speed;
float velocityChange = Math.Min(speed, deceleration);
Body.LinearVelocity -= velocityChange * horizontalDirection;