0 votes

Well, I'm doing a 3D FPS and this is my first 3D project; I have a good knowledge of Godot 2D, but thinking about 3D has still been an obstacle.

In this case, I want to make an enemy bullet that takes the player's starting position as a reference to follow a straight line, but without following the player after that. Kind of like the Imp bullet in the classic Doom.

In this case, I was doing something like this, taking the bullet from the Godot tutorial and modifying it, but it turns out that, obviously, in this mechanism the direction of the bullet remains the Z of the player, so that if the player moves, the enemy's bullet chases him by Z position.

that said, what would be the best solution for this not to happen? i'm stuck and i can't illuminate at all.

    extends Area

onready var player = get_parent().get_node("Player")
var speed = 2


func _physics_process(delta):
    var forward_dir = player.global_transform.basis.z.normalized()
    global_translate(forward_dir * speed * delta)
in Engine by (170 points)

1 Answer

+1 vote
Best answer

You don't show how/where the bullet is created and, more importantly, how you're defining the parent/child relationship of the new bullet object when adding it to scene.

If your bullet is moving with the player, that probably means that you've made the new bullet a child of the player - which would cause exactly that problem.

You need to make the bullet a child of the scene itself, so it's not associated with the transform position of the player.

by (10,896 points)
selected by

It wasn't the kind of response I expected - and my code information was really incomplete - but you helped me solve the problem and I was able to organize my thinking, thank you very much = D.

In fact, the whole problem consisted of the nodes and their organization between parent () and child () and how I instance () in creating the bullet.

now, with the right information, it’s working well.

Thanks

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 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 webmaster@godotengine.org with your username.