- Home /
Check if skateboard is grounded
I'm making a skateboarding game and when the skateboard is in the air, I want it to be able to rotate with the arrow keys. This is the code i'm currently using:
//Check if grounded
function OnCollisionEnter(){
isGrounded = true;
}
function OnCollisionExit(){
isGrounded = false;
}
function Update()
{
if(isGrounded == false && Input.GetAxis("Horizontal")){
transform.Rotate(-Input.GetAxis("Horizontal") * Vector3.forward * FlipSpeed);
}
}
And this works quite well, however, if the skateboard were to hit a ramp side-on, and then move away from the ramp, it would think it is in the air and therefor rotate when the arrow keys are pressed, which is not what I want.
Is there a better way of checking it is grounded?
maybe u have to consider the side of the collision to make ur skater and skateboard react to it
But even if you go onto a ramp, the board hits the ramp with it's front wheels and then leaves the terrain with it's back wheels, and therefor the script still thinks the board is in the air when it is on the ramp, even though the collision is from underneath.
are u using character controller? there is a isGrounded function, and some collision flags like top or sides.
http://docs.unity3d.com/Documentation/ScriptReference/CharacterController.html
Answer by nventimiglia · May 21, 2013 at 03:23 PM
Check the tag of the collision
Use a raycast from the skateboard to the ground.
How would I go about doing that second option? I'm quite new to unity.
Your answer
Follow this Question
Related Questions
Collision.point not working 1 Answer
Can't detect isgrounded? Help 1 Answer
Grounded Only on One Layer 1 Answer
Problem with Rigidbody control script! (collision with perpendicular walls problem) 1 Answer
What does it mean to be "grounded"? 0 Answers