- Home /
The question is answered, right answer was accepted
Addforce ignores Rotation ?
So I have a Bullet that I want to disappear after 1 second and instantiate 8 smaller bullets that will fly in 8 directions. Here is an example of 2 bullets:
Shott1 = GameObject.Instantiate(Bulle, transform.position, transform.rotation);
Shott1.GetComponent<Rigidbody>().AddForce(transform.right * 300f);
Destroy(Shott1, 1.5f);
Shott2 = GameObject.Instantiate(Bulle, transform.position, transform.rotation);
Shott2.transform.Rotate(0, 0, 90);
Shott2.GetComponent<Rigidbody>().AddForce(transform.right * 300f);
Destroy(Shott2, 1.5f);
So the first bullet is as it should, but second should rotate 90 degrees and then go it's right, but it ignores rotation and goes in the same direction as the first bullet. I would use "transform.up" but I want bullets to go in 8 directions, not 4 (right,up,-right,-up and between). I would Instantiate them in a good direction but I don't understand what "w" is in Quaternion.
Answer by Harambe_Reborn · Aug 15, 2019 at 02:53 PM
Instead of AddForce() use AddLocalForce() with a direction of transform.x.
I in my version there isn't AddLocalForce() but there is sth called AddRelativeForce but when I use it with:
"transform.right" doesn't work (bullet goes not in the direction it was rotated to)
"transform.x" says that there I can't write "x"
"transform.rotation.x" says it can't convert float to Vector3
"(new Vector3(1,0,0)" bullet that goes in the same direction is ok, but second bullet (rotated 90 degrees) is still in one place
"(new Vector3(transform.rotation.x, transform.rotation.y, transform.rotation.z)" either doesn't work
take a second and think of what you wrote.
you want to take the rotation of the bullet into account and not the rotation of the object whatevery your script is on....
take
Shott2.transform.rightand you should be fine...
In general, even if it is not the best form of debugging: check the vectors you choose by a debug.log to see if it is actually the result that you hope for.
Oh... So, as usual, I am making simple/stupid mistakes. Anyway, thank you.