- Home /
Rigidbody2d not rotating
GameObject bullet = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
Rigidbody2D brb = bullet.GetComponent<Rigidbody2D>();
brb.AddForce(firePoint.up * bulletForce, ForceMode2D.Impulse);
fireRB.rotation += 45;
The script for my Shoot function. I want the object to shoot, then rotate 45 degrees, but the rotate part does not work. Everything else seems to be working fine, just not the rotate.
Update: The first few times it shoots, it does not rotate, but after shooting 5 or so times, it starts rotating again.
Answer by Fuzzymoth_Games · Dec 10, 2020 at 08:33 PM
I finished it. I used fireRB.gameObject.Transform.Rotate().
Answer by qsp18 · Dec 08, 2020 at 05:34 PM
rotation is a matrix - like a vector of 4 components.
Better use: fireRB.gameObject.transform.rotation.eulerAngles
This is a vector and then you have to specify which component of the vector to change. In 2D it should be the Z. So you have to write:
fireRB.gameObject.transform.rotation.eulerAngles.z = new Vector3(fireRB.gameObject.transform.rotation.eulerAngles.x, fireRB.gameObject.transform.rotation.eulerAngles.y, fireRB.gameObject.gameObject.transform.rotation.eulerAngles.z + 45)
i used fireRB.gameObject.transform instead of fireRB, to change the values of the transform
It caused an error: "Cannot modify the return value of Quaternion.EulerAngles because it is not a variable".
Your answer
Follow this Question
Related Questions
How to rotate your character C# 1 Answer
Rigidbody rotation problem 0 Answers
Make sphere rotate when controlled 7 Answers
Strange rotation pattern. 0 Answers