How to make a 3D bullet that takes the player's position for direction but then continues in a straight line?

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

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)
:bust_in_silhouette: Reply From: jgodfrey

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.

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

lucasfazzi | 2020-02-10 02:30