My bullet fired in a strange direction. I urgently need help!

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Sutthida_JR

The first time I made a game in godot was a top down shooter and it was a school project. My only problem right now is that when the enemy turns to shoot the player in any direction, the enemy’s bullets don’t fire in the player’s direction. It fired to the right and I don’t know why.

I use the same shooting script that I use in the player. and in player it can work perfectly

I followed the tutorial of two channels on YouTube.
https://youtu.be/HycyFNQfqI0 ( just script shooting )
and
https://www.youtube.com/watch?v=aY-B_5fYUos ( everything except the script in weapon)

i will post the picture here

The Bug

The Shooting Code!
AI Code 2
AI Code 1

if you dont see the pic
the bug :Imgur: The magic of the Internet
The Shooting Code: Imgur: The magic of the Internet
AI Code 1:Imgur: The magic of the Internet
Ai code 2:Imgur: The magic of the Internet

Are your bullets physics objects, e.g. StaticBody, RigidBody etc…, and if so, which one?

SteveSmith | 2022-11-21 16:06

I know it sounds simple but are you sure that the position2d node you are using is in the right place in your enemy node?

Gluon | 2022-11-21 22:44

it’s Rigidbody but i use static too(just to enter body)

Sutthida_JR | 2022-11-21 23:11

Can you elaborate more, I’m not using position2dnode I wrote the bullet code like this channel:https://youtu.be/HycyFNQfqI0 but just add static to (enter the body)

Sutthida_JR | 2022-11-21 23:17

So what is the end_of_ship which is being used to provide the position?

Gluon | 2022-11-21 23:21

It’s the end of the spaceship in the game. I made it so that the bullet would fire from the end of the spaceship. It works normally as a player script.

Sutthida_JR | 2022-11-21 23:26

Sorry i mean what kind of node is it? I assumed it was a position2d node but I guess from your other response it isnt. Also are you instancing the enemy or has it been added in the editor to the level scene? Have you tried adding the enemy at different points and seeing if the shot starts at different positions relative to your enemy?

Gluon | 2022-11-21 23:32

Sorry, I actually misunderstood. I actually use this position2D node (change name to end_of_ship) And I’ve added enemy to level scene. The result is Enemy can turn around to the player and fired but the problem is it can’t fire direct to player it always fire to the right side and if the enemy turn to the left side opposite of right where bullet fired it’s make damge to itself too…

Sutthida_JR | 2022-11-22 06:19

Here more :

  1. more - Album on Imgur

(enemy scene+shooting code)

  1. Debug.mp4 on Vimeo

( result in mp4 format )

  1. Imgur: The magic of the Internet
    ( Bullet Script )

Sutthida_JR | 2022-11-22 14:32