I am new to this engine. So I need help in this basic stuff. I read the other similar question but didn’t get satisfactory answers.
Basically I am developing 2D game using tk2d plugin. I want to move my ball constantly on screen.
float ballMagnitude = rigidbody.velocity.magnitude;
if (ballMagnitude < VELOCITY)
{
Vector3 ballVelocity = new Vector3(VELOCITY, VELOCITY, 0f);
rigidbody.velocity = ballVelocity;
}
But this code creates problem when ball direction change. So I need help in this stuff.
If you want more detail then I am ready to provide. Thanks for your intention.
After some what research I have following code :
if (!isPaused)
{
float ballMagnitude = rigidbody.velocity.magnitude;
print("ball magnitude : " + ballMagnitude);
if (ballMagnitude < SPEED)
{
Vector3 ballVelocity = new Vector3(VELOCITY * (Mathf.Abs(rigidbody.velocity.x) / rigidbody.velocity.x), VELOCITY * (Mathf.Abs(rigidbody.velocity.y) / rigidbody.velocity.y), 0f);
rigidbody.velocity = ballVelocity;
}
}
if (Input.GetMouseButtonDown(0) && isPaused)
{
Vector3 ballVelocity = new Vector3(VELOCITY, VELOCITY, 0f);
rigidbody.velocity = ballVelocity;
isPaused = false;
}
Using this code, the object moves constantly but it show some jerks in its movement. How to reduce this one?
What problems happens when you change direction?
– Womrwood