Answer the question
In order to leave comments, you need to log in
How to make Linear Drag not affect Y axis (Unity)?
I'm making controls for the game. It is necessary that the object moves up all the time with the same speed, and moves left and right with the finger. I apply force or speed along the X axis and so that the object can stop I add Linear Drag.
But it also affects the Y-speed.
How can I make Linear Drag not affect the Y-axis?
Do not swear for a lot of GetComponent, I'm just testing for now, then I'll put everything in order.
if (direction == 0)
{
GetComponent<Rigidbody2D>().AddForce(new Vector2(0,0));
GetComponent<Rigidbody2D>().velocity = new Vector2 (0, 1.5f)*3f;
}
else if (direction > 0 && transform.position.x >= initial_pos + (width*direction)/2f)
{
GetComponent<Rigidbody2D>().AddForce(new Vector2(0,0));
GetComponent<Rigidbody2D>().velocity = new Vector2 (0, 1.5f)*3f;
}
else if (direction < 0 && transform.position.x <= initial_pos + (width*direction)/2f)
{
GetComponent<Rigidbody2D>().AddForce(new Vector2(0,0));
GetComponent<Rigidbody2D>().velocity = new Vector2 (0, 1.5f)*3f;
}
else if (direction > 0 && transform.position.x != initial_pos + (width*direction)/2f)
{
GetComponent<Rigidbody2D>().velocity = new Vector2 (0, 1.5f)*3f;
GetComponent<Rigidbody2D>().AddForce(new Vector2(0.02f,0));
}
else if (direction < 0 && transform.position.x != initial_pos + (width*direction)/2f)
{
GetComponent<Rigidbody2D>().velocity = new Vector2 (0, 1.5f)*3f;
GetComponent<Rigidbody2D>().AddForce(new Vector2(-0.02f,0));
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question