velocity behaviour - can't make velocity to 0.
Hello there.
I am new to Unity I am trying to do something like minigolf. I have a sphere and there is a statement - if velocity.zero then player can drag-shot again. But after first shot velocity doesn't go down to zero, just zeros and one value is 0.1 or -0.1 e.g (-0.1, 0, 0) or (0, 0, 0.1).
Use Gravity = true is kinematic = false drag = 3 mass = 1
Here's my code if I am doing something wrong:
void FixedUpdate() { Debug.Log(rb.velocity);
if (rb.velocity == Vector3.zero)
{
if (Input.GetMouseButtonDown(0))
{
currentpos = Input.mousePosition;
}
if (Input.GetMouseButtonUp(0))
{
releasepos = Input.mousePosition;
force = currentpos - releasepos;
force.z = force.y;
force.y = 0;
rb.AddForce(force * speed);
}
}
float velx = rb.velocity.x;
float vely = rb.velocity.y;
float velz = rb.velocity.z;
if ((velx <= maxToStop && velx >= minToStop) && (vely <= maxToStop && vely >= minToStop) && (velz <= maxToStop && velz >= minToStop))
{
rb.velocity = Vector3.zero;
Debug.Log("0");
}
}
}
Looks like the last block of code where I try to force velocity to 0 doesn't make any difference.
Your answer
Follow this Question
Related Questions
Character suddenly stop moving. 0 Answers
How to Get Speed to Very Gradually Pick Up Over Time? 2 Answers
dash till puff game 0 Answers
Rigidbody2D is falling slowly when using velocity 1 Answer
Strange behavior when applying forces. 0 Answers