Question How to calculate position with inclination

Discussion in 'Physics' started by huseyin1030, Feb 16, 2021.

1. huseyin1030

Joined:
Jan 20, 2018
Posts:
2
Hello,

I would like to use moveposition on rigidbody but the target position has to be calculate with a rotation without rotating my player.

My player move with this way :

Code (CSharp):
1. rb.MovePosition(transform.position + transform.forward * Time.fixedDeltaTime * speed);
When an inclination occur, I would like to move above the inclination without rotating my player.
I have the inclination angle (Vector3).

Thanks

2. AlTheSlacker

Joined:
Jun 12, 2017
Posts:
326
Sorry, I am probably completely missing the problem here... You want to move your body up a known angle slope and wish to know the new y position?

If so, you can use Mathf.Tan(angle) [angle is in radians] * horizontal distance to get the vertical (y) change.

If you want constant speed, then Vector3.Clamp it to the displacement you require.

I'm assuming you are not going anywhere near a 90 degree slope? Tan is not the approach for that problem.