Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Member variables
- float JumpUpVelocity;
- float GravDownAcceleration;
- vector3 Position;
- vector3 Velocity;
- vector3 Acceleration;
- void CalcParameters(float InFootSpeed, float InJumpHeight, float InJumpWidthToPeak)
- {
- JumpUpVelocity = 2.0f * InJumpHeight * InFootSpeed / InJumpWidthToPeak;
- GravDownAcceleration = -2.0f * InJumpHeight * InFootSpeed * InFootSpeed / (InJumpWidthToPeak * InJumpWidthToPeak);
- // Assumes +Z is up, swizzle as necessary.
- Acceleration = vector3(0, 0, -GravDownAcceleration);
- };
- void Jump()
- {
- // TODO: Make sure we're standing on the ground unless we want to allow air jumping.
- // Assumes +Z is up, swizzle as necessary.
- // Can't change X or Y unless we deliberately want to alter lateral movement when jumping.
- Velocity.z = JumpUpVelocity;
- }
- void Update(float DeltaTime)
- {
- // Velocity Verlet integration given the simple case of constant acceleration.
- // This should run once per frame.
- Position = Position + ((Velocity * DeltaTime) + (Acceleration * DeltaTime * DeltaTime * 0.5f));
- Velocity = Velocity + (Acceleration * DeltaTime);
- }
Add Comment
Please, Sign In to add comment