Im currently making a simple ball movement script, everything works fine; however Im trying to improve the jump portion of the script. I want it to jump when its grounded(I have that part done) and when the surface its trying to jump on is a valid angle. A valid angle would be an x or z angle that isn’t 90 degrees or less(could also be not -90 degrees or more). So to sum up: How can I detect the angle of a surface on a plane or a multi sided surface?
The current code partially works, its checking the angles of the game object, not the surface its colliding with; therefore if the angle is valid you can jump on any side you collide with, and if its invalid then you cant jump on it at all.
code:
public bool isGrounded = false;
public bool angleJump = false;
void Update()
{
.
.
.
if(Input.GetKeyDown(KeyCode.Space) && isGrounded && angleJump)
{
rb.AddForce(jumpDir * jumpF , ForceMode.Impulse);
isGrounded = false;
angleJump = false;
}
}
private void OnCollisionEnter(Collision other)
{
if(other.gameObject.tag == "WorldSurface")
{
isGrounded = true;
if(other.transform.eulerAngles.x<90 ||other.transform.eulerAngles.z<90||other.transform.eulerAngles.x>-90|| other.transform.eulerAngles.z>-90)
{
angleJump = true;
if(other.transform.eulerAngles.x>=90 ||other.transform.eulerAngles.z>=90 ||other.transform.eulerAngles.x<=-90 ||other.transform.eulerAngles.z<=-90 )
{
angleJump = false;
}
}
}
}

