Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Viribus |
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 move_and_collide() 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: