- Home /
How to get angle of terrain?
Hi! I'm developing a game for my final year project and it is a bike simulator game that uses a real bicycle as an input through Arduino and has a moving platform based on the angle of bike in the game. I want to get the angle of the terrain where the bicycle is oriented. I have searched but can't find the right solution. I think, to get the angle is to use raycast functon or Vector3.angle.
Please help me. Thanks
Answer by FTdevelopment · Aug 05, 2014 at 07:31 PM
ALTERNATIVE WAY : 1-Create a little box. 2-Assign Rigidbody to the box. 3-Put the box where you want to know angle of terrain. 4-Get box's angle values.
(Also you can get bicycle's current angles)
Maybe this can help to you.
(Also you can get bicycle's current angles)
Thats what I was hinting at with my SOH CAH TOA link :P - The X and Z angles are there in the transform, of course this doesnt help deter$$anonymous$$e the slope if you are not On the slope.
Hi! Here's my code. It gets the angle and also orients the bike to the terrain using raycast. I'm not sure about the output of angle if its accurate. Can you look at the code?
RaycastHit hitA;
if(Physics.Raycast(transform.position + transform.forward, -transform.up, out hitA))
{
RaycastHit hitB;
if (Physics.Raycast(transform.position - transform.forward, -transform.up, out hitB))
{
transform.forward = (hitA.point - hitB.point) * Time.deltaTime;
}
}
angle = (($$anonymous$$athf.Atan2(transform.position.y, transform.position.x) * $$anonymous$$athf.Rad2Deg));
Your answer
