This question was
closed Nov 13, 2017 at 09:47 AM by
GuysInSuits for the following reason:
Found the problem myself
Question by
GuysInSuits · Nov 11, 2017 at 05:12 PM ·
rigidbody2dvelocity
Object won't move even with velocity
I got the problem that my object won't move when I apply a velocity in.
Rigidbody2D Rigidb;
float MovingSpeed = 5f;
void Awake()
{
Rigidb = GetComponent<Rigidbody2D>();
}
void MoveObject(Vector3 destination)
{
Vector3 dirVector = destination - transform.position;
bool x = false, y = false;
if (dirVector.x < 0)
{
x = true;
dirVector.x = -dirVector.x;
}
if (dirVector.y < 0)
{
y = true;
dirVector.y = -dirVector.y;
}
if (dirVector.x > dirVector.y)
{
dirVector = dirVector / dirVector.x;
}
else
{
dirVector = dirVector / dirVector.y;
}
if ((x && dirVector.x > 0) || (!x && dirVector.x < 0)) dirVector.x = -dirVector.x;
if ((y && dirVector.y > 0) || (!y && dirVector.y < 0)) dirVector.y = -dirVector.y;
Rigidb.velocity = new Vector2(dirVector.x * MovingSpeed, dirVector.y * MovingSpeed);
}
In my testcases the velocity ends up being (0.0, 5.0) but even though it just won't move. It isn't kinematic and the x and y movement isn't frozen either.
Comment