Question by
danmct1995 · Apr 29, 2020 at 07:54 PM ·
2drigidbody2dvelocityphysics2daddforce
Trying to add force to an object... is this done correctly?
I just want to add 1 force unit in the direction the object is moving when it is traveling between the mentioned speeds on its respective axes. Is this done properly to add force to the object?
public void FixedUpdate()
{
/* X axis adjustment */
if (rb.velocity.x > 0f && rb.velocity.x < 0.3f)
{
rb.AddForce(Vector2.right);
}
else if (rb.velocity.x > -0.3f && rb.velocity.x < 0f)
{
rb.AddForce(Vector2.left);
}
/* Y axis adjustment */
if (rb.velocity.y > 0f && rb.velocity.y < 0.3f)
{
rb.AddForce(Vector2.up);
}
else if (rb.velocity.y > -0.3f && rb.velocity.y < 0f)
{
rb.AddForce(Vector2.down);
}
}
Comment
Your answer
Follow this Question
Related Questions
Climbing code problem (2d physic). 0 Answers
Adding velocity to an object in a brick breaker game 0 Answers
How to stop the character moving after the button is pressed, using Rigidbody2D()..AddForce? 1 Answer
Rigidbody follow player and maintain all physical properties 1 Answer
Arkanoid-like bounce troubles 1 Answer