- Home /
2d controll rigidboy.velocity.y
Hi guys, i'm having a problem trying to program in unity 5.
i've watched tutorials, but are only for 4.6, and the most used comand for controll jump and walk simultaneously, they use: new Vector2 (walkSpeed, Rigidbody2D.velocity.y)
(walkSpeed is a public float)
But in Unity 5 does not exist "Rigidbody2D.velocity.y" what can i use?
Answer by DoTA_KAMIKADzE · Apr 19, 2015 at 10:43 PM
You can as well create a variable for y like you do for x.
Or you can get your actual rigidbody (what you show above is incorrect) if your object has rigidbody, do something like this instead:
private Rigidbody2D rigi;
void Awake()
{
rigi = GetComponent<Rigidbody2D>();
}
//then in your code:
new Vector2 (walkSpeed, rigi.velocity.y)
If that rigidbody is not contained in the object which contains your script instance then you can either use Find or parenting to find and assign rigi variable or make it public/[SerializeField] and assign from Inspector.
Your answer
Follow this Question
Related Questions
2D Character jittering after build. (Unity 5) 1 Answer
Unity2D game objects don't collide 1 Answer
Unity2d android. Box keeps moving after taking away accelerometer controls 2 Answers
Avoiding 2D top-down diagonal movement 2 Answers
box collider goes slightly into another box collider (not triggers) 1 Answer