0 votes

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 )
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 :https://imgur.com/a/g0wGWVA
The Shooting Code: https://imgur.com/n1HI35Z
AI Code 1:https://imgur.com/8rEP9qI
Ai code 2:https://imgur.com/8rEP9qI

Godot version v3.4.4.
in Engine by (12 points)
edited by

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

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?

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

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)

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

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.

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?

Sorry, I actually misunderstood. I actually use this position2D node (change name to endofship) 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...

Here more :

1) https://imgur.com/a/XuNbhl3

(enemy scene+shooting code)

2) https://vimeo.com/773815846

( result in mp4 format )

3) https://imgur.com/B0ViYiR
( Bullet Script )

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.