- Home /
How to keep a gameobject on the ground ?
Hello friends,
I am learning to develop a 2d game and I want to make an endless runner. The maincharacter is a skier, who is sliding down a hill and who has to overcome random challenges. But there is the first problem. I don't know how to keep the skier on the ground until I press "jump". The skier is flipping forwards while sliding :D
Can you give me a hint how to solve this ?
Answer by TheMatrixAgent22 · Oct 03, 2018 at 06:21 PM
Just add a rigidbody to your character, should work... not sure if rigidbody2d supports gravity. If it doesn't, then make a function, where your y position gets decreased over time. For example:
public class BallController : MonoBehaviour {
public float gravity;
void Update () {
Gravity();
}
void Gravity () {
transform.position.y -= gravity;
}
}
Hope it helps!
The code I made, is actually (probably :P) the best way to make gravity. Stick to that!
Hey thank you ! I will try it out and let you know if it works :D
Your answer
Follow this Question
Related Questions
GameObject not detecting collision with floor 0 Answers
Physics2D Overlapbox not working as aspected 0 Answers
Collision bug 0 Answers
Player 2D getting stuck while moving 2 Answers