- Home /
Box Collider won't rotate with Bullet
It's difficult to describe what's going on, so I got a screencap of the glitch occuring with a diagram of what, specifically, is happening.

This does not seem to happen all the time, but many projectiles spawn with crooked 2D colliders. It is a bullet, so the collider is supposed to be long, but roughly 50% of the time, they seem to be horizontally oriented as seen in the diagram above, with the tail end pointing towards the left, no matter which direction the bullet is traveling. It functions fantastically when the player is to the immediate right, but on the left it is very glitchy.
And yes, the bullet is supposed to bounce like that.
The screenshot shows an example of this collider glitch in action, catching itself on the side of an object it would have ordinarily been able to pass by without touching should the collider have been oriented correctly.
From my own debugging, it looks like the projectiles that are behaving oddly have their Z rotations fixed to 90. When the bullets are moving, their rotations should be reflected in the Z axis, I just think there's a reason it's being fixed to 90.
Here's the code that spawns these projectiles
dir = target.position - player.position;
dir = dir.normalized;
Rigidbody2D Shot;
Shot = Instantiate (ProjectileTest, target.position, Quaternion.Euler (dir)) as Rigidbody2D; //target is where the bullet spawns from, player is what is being shot at.
Shot.velocity = transform.TransformDirection (Vector3.forward * bulletspeed);
Shot.transform.Rotate (Vector3.forward);
So any idea why the collider does this?
Your answer