Hello everyone,
I’ve been working on a 2D platformer game for a bit. But I’ve had a problem with the rotation of my player character’s gun and the bullets being fired from it, which I’ve been stuck on for quite a while now. The idea is to rotate the gun and fire projectiles towards the mouse location. This more or less works fine when facing the right (the default scale).
[76563-facingright.png*_|76563]
However, when I face my character left, the vertical rotation is reversed, and I’m unable to find a decent solution to this.
[76568-facingleft.png*_|76568]
The character and weapon are build in the hierachy as follows:
Player
- gunArm
- Weapon
- FirePoint
- WeaponModel
The flipping is done by flipping both the player and the gunArms x-scale:
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
Vector3 armScale = gunArm.transform.localScale;
armScale.x *= -1;
gunArm.transform.localScale = armScale;
The projectile fired takes the same rotation as a firePoint object attatched to my gun:
for (int i = 0; i < firePoints.Length; i++) {
nextShotTime = Time.time + fireRate;
Projectile newProjectile = Instantiate (projectile, firePoints_.position, firePoints*.rotation) as Projectile;*_
}
During the testing I did find out that the projectile does indeed take the same rotation as my gunArm in the inspector, however the actual rotation is reversed. I’ve tried a whole lot, but always end up with this, or worse. Any help would be appreciated. In fact, any advice concerning rotation, Quaternions and all that is appreciated; these are a stumbling block everytime I encounter them.
_*
_*