Hello,
So weird thing happening, I am instantiating a prefab projectile but it doesn’t seem to want to go forward…
I have a weapon script attached to the player GO:
Vector3 muzzlePosition = transform.position + transform.forward;
//todo OMG POOL
var projectileGO = Instantiate(prefab, muzzlePosition, transform.rotation, ProjectileContainer.transform);
Debug.Log("Player is facing: " + transform.rotation.eulerAngles + " and projectile is facing: " + projectileGO.transform.rotation.eulerAngles);
The Projectile class has a simple line in FixedUpdate:
transform.Translate(transform.forward * _speed * Time.fixedDeltaTime);
The player object is facing right (0, 90, 0) at the start.
Like this the projectile fires to the right from the player’s position (so in the direction of Vector.backward) and the log shows:
Player is facing: (0.0, 90.0, 0.0) and projectile is facing: (0.0, 90.0, 0.0)
The log entry looks correct to me but the projectile is still going right…
At first I thought the projectile rotation at 0,90,0 is relative to player so it would be logical to go right so I tried a quick:
var projectileGO = Instantiate(prefab, muzzlePosition, transform.rotation * Quaternion.Euler(0, -90, 0), ProjectileContainer.transform);
Which yield a log of:
Player is facing: (0.0, 90.0, 0.0) and projectile is facing: (0.0, 0.0, 0.0)
But the projectile is now going towards the left side of player (which is correct)!
Can anyone see what I am doing wrong?