- Home /
Question by
Zeke-27 · Mar 19, 2019 at 09:11 AM ·
2d-platformer2d-physics2d-gameplay
How to keep Y velocity normal?
I've got a 2D object with a rigidbody2D attached but it falls really slowly for some reason. I'm using velocity to move it left or right but I want the falling movement on the Y axis to be normal. How would I do this?
private Vector2 velocity;
[SerializeField]
public Rigidbody2D rb;
public float mouseSpeed;
void Update()
{
if (Input.GetMouseButtonUp(0))
{
velocity = new Vector2(mouseSpeed, 0);
}
}
void FixedUpdate()
{
rb.velocity = velocity;
}
Comment
Stop setting its Y velocity to zero would be a good start. Use Rigidbody.Addforce ins$$anonymous$$d of setting the velocity directly
Answer by xxmariofer · Mar 19, 2019 at 09:14 AM
you are setting the velocity to 0, just dont change it
velocity = new Vector2(mouseSpeed, rb.velocity.y);
I tried that but it still falls at the same slow speed :/
What is the gravity set at? Playing with the gravity in the rigidbody component should affect this
I've tried setting the rigidbody gravity to higher numbers and it makes him fall correctly but makes him move much slower.