Question by
sethfrizzle · Apr 07, 2021 at 10:20 PM ·
rotationcollisionphysics2d
I have two RaycastHit2Ds but only one is activating
I have a player game object that gets launched in the opposite of the direction you drag it. I tried using multiple RaycastHit2Ds to make it so the game object rotates to stand on the surface it lands on. However, only one of the RaycastHit2Ds activates. Can anyone tell me why this is happening and how to fix it please?
The code BTW:
void OnCollisionEnter2D(Collision2D col)
{
RaycastHit2D Upcheck = Physics2D.Raycast(Up.position, Vector2.up, 0);
RaycastHit2D Downcheck = Physics2D.Raycast(Down.position, Vector2.down, 0);
if (col.gameObject.tag == "Surface")
{
landed = true;
rb.velocity = Vector3.zero;
anim.SetFloat("Jump", 0);
if (Upcheck.collider.tag == "Surface")
{
obj.transform.rotation = new Quaternion(0, 0, 180, 0);
}
if (Downcheck.collider.tag == "Surface")
{
obj.transform.rotation = new Quaternion(0, 0, 0, 0);
}
}
}
Comment