Trouble with my shot orientation

Hi,
I’m pretty new into scripting, and I have a problem with my shooting mechanic.
I am making a 2D game in a 3D environment. The problem is pretty straight forward, when I shoot, my bullet doesn’t go where I am aiming at all, and some angle just can’t have bullet at all. I have made a small cylinder as a spawn point for my bullet and made the cylinder follow the mouse in the game. All of this follows my Z axis,

  • At 0° to 90° on the Z, the bullet goes straight down to progressively forward
  • between 90°to 180° the bullet goes forward
  • from -180° to -90° (180°-270°) the bullet goes backward
  • from -90° to 0 (270-0) the bullet goes backward but progressively downward as well

Also te projectile can’t go up for some reason, even if my spawn point can.

The following script is the one I used for that matter.

Thank you a lot for your help, and sorry for the bad English, french in my main language.

5864176–623725–PlayerController.cs (1.94 KB)
5864176–623731–SpawnOrientationScript.cs (711 Bytes)

Hi! Is your SpawnOrientationScript working? If so, I think the problem comes from this line, and you may try changing it this way:

//teleportPoint.GetComponent<Rigidbody>().AddForce(new Vector3(shotSpawn.rotation.z, 0, 0) * shotSpeed, ForceMode.Impulse);

teleportPoint.GetComponent<Rigidbody>().AddForce(shotSpawn.right * shotSpeed, ForceMode.Impulse);

Let me know if it works :smile:

1 Like

you’re a life savior. I didn’t know direction existed in unity. Thank you