- Home /
How can I increase or decrease a position based on another variable ?
My question is simple and somewhat straight forward. I want to increase or decrease a gameobject's position based on another gameobject's rigidbody velocity. Thanks in advance for help !!
Answer by suIly · Dec 12, 2020 at 05:59 PM
In the script, type this code:
public Rigidbody thisRigidbody;
public Rigidbody otherRigidbody;
private void LateUpdate()
{
thisRigidbody.velocity = otherRigidbody.velocity;
}
make sure to assign the rigidbodies, and use "Rigidbody2D" if you're in a 2D scene.
Hello ! $$anonymous$$y problem actually is adding (or substracting, if a velocity axis is negative) a gameobject's velocity to an already defined different gameobject position. I've tried simply adding the two vectors together in the Update function, but it keeps adding until infinity.
Rigidbody velocity isn't a position, its simple a value that adds to the position. If you set it to 0, the object won't move to x position 0, it will just stay still. Changing the velocity to 1 just moves it forward until you change it to 0, not set the position to 1.
Your answer
Follow this Question
Related Questions
Take final position after a force applied to a GameObject 1 Answer
Rigidbody Disable Velocity/Movement? 1 Answer
Get Interpolated rigidbody velocity 1 Answer
Why is my rigidbody.velocity not working? 1 Answer
Dragging object out of position 2 Answers