- Home /
Rigidbody not responding to uphill/downhill acceleration
Hi, so I want my player to be able to rotate without losing any speed (their velocity is always pointed down their forward vector), but when I do this I get speed capped, regardless of whether I'm going downhill or not. Here is the code:
void FixedUpdate()
{
m_vForce = transform.forward;
m_vForce.y = 0.0f;
rigidbody.AddForce(m_vForce * m_fAcceleration);
float fLateralSpeed = new Vector2(rigidbody.velocity.x, rigidbody.velocity.z).magnitude;
Vector3 vNewVel = new Vector3(transform.forward.x * fLateralSpeed, rigidbody.velocity.y, transform.forward.z * fLateralSpeed);
rigidbody.velocity = vNewVel;
}
The reason I'm setting force's y value to 0 is because it gets it's transform from the camera which is slightly angled into the ground. Been stuck on this problem for a while now and have tried quite a few workarounds and hacks, not getting the job done as expected.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613085158im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Trying to make a Projectile Rotate and Move Forward.. 1 Answer
Rotating a Rigid Body and moving Forward 4 Answers
Keeping transform.forward facing forwards 1 Answer
look at movedirection 1 Answer