- Home /
Problem is not reproducible or outdated
Velocity in rigidbody2d is not doing anything.
I'm trying to make my jump when the W key is pressed. I'm going to achieve this with the rigidbody2D.velocity route since the game is 2D. Here's my code.
//jumping
if(canJump == true){
rigidbody2D.velocity.y =10;
Debug.Log("This shows up");
}
}
function OnCollisionStay2D(coll: Collision2D) {
if(coll.gameObject.tag == "Terrain" && Input.GetKeyDown(KeyCode.W)){
canJump = true;
}
else{
canJump = false;
}
}
Anyways, when I press W, the debug log string shows up, but the rigidbody.velocity = 10 is not seeming to have an effect. What is wrong? Thank you!
$$anonymous$$aybe you added RigidBody component ins$$anonymous$$d of RigidBody2D. Please check this post: rigidbody2d.velocity.y not working
You can't do rigidbody2D.velocity.y =10;
because, Velocity is a member variable of rigidbody2D and is an instance of calss Vector2.
Answer by ziv03 · Jan 04, 2014 at 12:06 AM
use rigidbody2D instead of Rigidbody2D. also if you're using c# you can't set the velocity y value by itself. you need to do:
rigidbody2D.velocity = new Vector2(rigidbody2D.velocity.x,3);
umm, I think we need to see more of your code to understand the problem. cause using rigidbody2D without a cappitle R should solve the instace problem. maybe you're changing the y velocity in another part in the code?
Anyway, need more of your code to find the problem.
I changed my question up a bit. And this is the only place it shows up. None of my other script has anything to do it.
Follow this Question
Related Questions
Setting Velocity of Rigidbody to Mouse Speed 1 Answer
(2D) Creating a border around the game 4 Answers
Rigidbody2D.velocity out of controll 3 Answers
how to jump at fixed height but faster 0 Answers