Projectile not shooting the right direction

I have the same problem as the other person mentioned, but the topic was closed without an answer :confused:

Setting shot.direction to global_transform.basis.z does not work.

I also noticed that when my code is like this @9:51 in the video, which is when the teacher made the turret look at the last enemy, but the firing direction is still at Vector3.FORWARD by default (as it should be as defined in projectile.script).

However, my turret does not behave like so. The projectile does not shoot at Vector3.FORWARD like in the video @9:51, but it will shoot the opposite direction of turret is looking.

I’m confused…and been stuck at this for days. Could you help me with this, please? Thank you very much!

Help us help you; can you post your code and a screenshot? Preferably a full screenshot so we can see your scene tree.

Working with the transforms of multiple inherited object scenes gets confusing fast, so don’t get discouraged. As a first step, you’ll want to check the rotations of all objects involved, including the projectile. Also, as a temporary workaround, does setting it to global_transform.basis.z * -1 fix the behaviour? This should not be treated as a full solution because the root cause of the problem might break something else later, but if that works, then you’ll have a better idea of what you’re looking for.

hi,

does the turret rotate to look at the enemies?
as the scene that rotates to look at the enemy is the basis for the projectiles direction.
in mine, I use the turret base as the rotation scene to make its chiltren rotate towards the enemy.

like in this snippit i have in the physics process of my turret.gd for the look at target, so setting my turret_base to look at the enemy.

is the ‘true’ in there at the end of the look_at? as this would cause it to be out by 180 degrees as that makes it use the model forward direction, instead of the defauly -Z direction.

if target:
		turret_base.look_at(target.global_position,Vector3.UP, true)

so using the Basis.Z from the turret_base, we set the projectile to have the same local rotation just down a little bit in the timer timeout method.

shot.direction = turret_base.global_transform.basis.z

but if thats not it, then definitely a little screen shot as BH mentioned, of your turret scene tree and the turret script would possibly help to try and squash the issue and get you back on track…

Darren

1 Like

Thank you BH67 and OboShape helping me!

I figured it out after taking a nap. I went back on the lecture to check what I was missing. Turned out just forgot to enable Top Level for the projectile, like the teacher said in 1-2 lectures ago :sweat_smile:

Such a small detail but it fixed everything!

Sorry for not including my code in the post. It would’ve been definitely more helpful!

2 Likes

Ah yes, the infamous power of the fabled nap XD

Congratulations, enjoy the rest of the course!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms