Question by
EZTheDev · Jul 06, 2021 at 09:23 PM ·
2drigidbody2d2d-physicsrigidbody.addforce
Rigidbody2D.AddForce inconsistent force amount
Hi all. I am having an issue with a projectile. When I press space I want it to have a force applied so that it can move. This seems to work fine, except that the force applied seems to be different every time. Sometimes it moves 10 units, other times it flies off the map (more than 200). Does anyone know why this happens?
Here is my code:
void Update()
{
if (Input.GetKey(KeyCode.Space))
{
//when we fire:
rb2d.constraints = RigidbodyConstraints2D.None;
//remove movement + rotation constraints
rb2d.AddForce(transform.right * velocity, ForceMode2D.Impulse);
//instead of this here call something in a fixedupdate
//apply force in direction facing
startRotating = true;
go = null;
gameObject.transform.SetParent(null, true);
//unparent projectile
}
}
Thank you,
EZ.
,
Comment
Your answer
Follow this Question
Related Questions
Moving Character to mouse click with Rigidbody2D! 0 Answers
Why/How 2d tower of blocks collapse? 0 Answers
How can I slow the movement of a single rigidbody2D? 2 Answers
Moving a Rigidbody2D relative to another object 0 Answers
How Do I make my character move? 0 Answers