0 votes

Hello, I am new to the Godot Engine (3D game dev. in general) and I am trying to make a 3d game where you pilot a spaceship. I have come across some difficulties in firing the projectiles from the turrets. My current system is that whenever a turret fires, it instances a my projectile at the position and rotation of a spatial node at the tip of the barrel. The projectile scene has an spatial node at the origin in order to keep the projectile from following the barrel when the turret rotates after the shot and a kinematic body with the mesh instance as a child. it uses the following code to move the projectile once it has been instanced. The problem is that I am currently changing the projectile's translation directly rather than using moveandcollide() because that way the script uses local coordinates (not sure if this is the correct terminology) rather than global coordinates. Because of this however, I don't think it properly interacts with the physics engine.

Here is the code I am currently using:

extends KinematicBody

var projectile_speed = 100.0

var projectile_range = 200.0

var projectile_pos = 0.0

var projectile_lifetime = projectile_range/projectile_speed

func _physics_process(delta):

    projectile_pos -= projectile_speed * delta
    self.translation.z = projectile_pos

    projectile_lifetime -= delta

    if projectile_lifetime <= 0.0:
        get_parent().remove_child(self)

And here is a screenshot of the projectile screen:
Projectile Scene

asked Aug 7 in Engine by Viribus (12 points)

1 Answer

0 votes

I'm also fairly new to Godot but shouldn't your position be stored in Vector 3 rather then floats.

answered Aug 8 by ZBot (64 points)
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.