- Home /
Rigidbody2d.AddForce behaving odd
I have a ship that shoots a laser.
I use something like
GameObject laserClone = Instantiate(laser,transform.position+(transform.up),transform.rotation)as GameObject;
laserClone.rigidbody2D.AddForce(transform.up* speed*Time.deltaTime);
I attached another script to the laser prefab to print the velocity.magnitude after 1/4 of a second. I have the speed set so that the velocity's magnitude is about 16. Most of the laser clones are within 0.01 of each other but occasionally and randomly some will have a velocity of 1-3. I cannot figure out why.
If anyone else has experienced something similar r has any idea what could be causing this any help would be appreciated. Thanks.
I have an instantiated prefab and the script with it adds a force in the Start(). It doesn't work. Neither does the Awake(). Update() works but then it's not the same speed as the original. $$anonymous$$ind of similar to yours. Sorry, don't have an answer.
Answer by Itaros · Oct 25, 2014 at 05:02 AM
Because at the time of the spawn you have frame time differences. Don't multiply by Time.deltaTime. But if you need to do something constantly and time-aware with rigidbodies switch to FixedUpdate() instead.
Your answer
Follow this Question
Related Questions
Rigidbody2D x velocity not moving unless placed in FixedUpdate 1 Answer
How do add force to the left (x-axis) 2 Answers
Problem with 2 Rigidbodies having respective colliders (2d) 1 Answer
Adding force to rigidbody2d to slide 1 Answer
Using direction and Rigidbody2D.AddForce() to move towards object. 1 Answer