Question by
Master_Piplup · Apr 10, 2017 at 01:05 PM ·
jumpstrafestrafing
Air Strafing
I've been having trouble figuring out how to fix movement in the air. Here's my current movement code:
Vector2 horizontalMovement = new Vector2(GetComponent<Rigidbody>().velocity.x, GetComponent<Rigidbody>().velocity.z);
if (horizontalMovement.magnitude > terminalVelocity)
{
horizontalMovement = horizontalMovement.normalized * terminalVelocity;
}
transform.rotation = Quaternion.Euler(0f, cameraObject.GetComponent<LookControl>().currentYRotation, 0f);
GetComponent<Rigidbody>().velocity = new Vector3(horizontalMovement.x, GetComponent<Rigidbody>().velocity.y, horizontalMovement.y);
sideTranslation = horizontalMovement.x;
frontTranslation = horizontalMovement.y;
Vector3 v3 = GetComponent<Rigidbody>().velocity;
if (grounded)
GetComponent<Rigidbody>().velocity = new Vector3(Mathf.SmoothDamp(horizontalMovement.x, 0, ref walkDecelerationVolx, walkDeceleration), 0, Mathf.SmoothDamp(horizontalMovement.y, 0, ref walkDecelerationVolz, walkDeceleration));
if (grounded)
GetComponent<Rigidbody>().AddRelativeForce(Input.GetAxis("Horizontal") * walkAcceleration * Time.deltaTime, 0, Input.GetAxis("Vertical") * walkAcceleration * Time.deltaTime);
else
GetComponent<Rigidbody>().AddRelativeForce(Input.GetAxis("Horizontal") * walkAcceleration * walkAirRatio * Time.deltaTime, 0, Input.GetAxis("Vertical") * walkAcceleration * walkAirRatio * Time.deltaTime);
When my character jumps, movement is restricted to a tenth (the value of walkAirRatio), but it slows down while in the air and does not conserve momentum from the run up. Any help would be appreciated
Comment
Your answer
Follow this Question
Related Questions
Make a rigidbody Jump (global up) 3 Answers
Multi-touch buttons 0 Answers
rigidBody.addforce doens't work like i want it to 1 Answer
This is frustrating 2 Answers
Need help with Character Jump! 0 Answers