Well I 'managed to solve most of my problems. I now have a traveling bullet, I cheated by using the GD bullet script from the FPS tutorial. When I tried to convert it to c#, the bullets just stay floating in place.
extends Spatial
var BULLET_SPEED = 70
var BULLET_DAMAGE = 15
const KILL_TIMER = 4
var timer = 0
var hit_something = false
func _ready():
$Area.connect("body_entered", self, "collided")
func _physics_process(delta):
var forward_dir = global_transform.basis.z.normalized()
global_translate(forward_dir * BULLET_SPEED * delta)
timer += delta
if timer >= KILL_TIMER:
queue_free()
func collided(body):
if hit_something == false:
if body.has_method("bullet_hit"):
body.bullet_hit(BULLET_DAMAGE, global_transform)
hit_something = true
queue_free()
VS
using System;
using Godot;
using Dictionary = Godot.Collections.Dictionary;
using Array = Godot.Collections.Array;
public class BulletScript : Spatial
{
// The speed the bullet travels at
public int BULLET_SPEED = 70;
// The damage the bullet does on whatever it hits
public int BULLET_DAMAGE = 15;
// NOTE: for both BULLET_SPEED && BULLET_DAMAGE, we are keeping their
// names uppercase because we do !want their values to change outside of
// when they are instanced/spawned.
// The length of time this bullet last (in seconds) before we free it.
// (because we do !want the bullet to travel forever, as it will consume resources)
public const int KILL_TIMER = 4;
public float timer = 0;
// A boolean to store whether || !we have hit something.
// This is so we cannot damage more than one object if we manage to hit more than one before
// this bullet is set free / destroyed
public bool hit_something = false;
public void _ready()
{
// We want to get the area && connect ourself to it's body_entered signal.
// This is so we can tell when we've collided with an object.
GetNode("Area").Connect("body_entered", this, "collided");
}
public void _physics_process(float delta)
{
// Get the forward directional vector && move ourself by it (times BULLET_SPEED && delta)
// NOTE: This is the bullet's local positive Z axis.
var forward_dir = GlobalTransform.basis.z.Normalized();
//GlobalTransform(forward_dir * BULLET_SPEED * delta);
GlobalTranslate(forward_dir * BULLET_SPEED * delta);
// A simple timer check that frees this node when the timer is done.
timer += delta;
if(timer >= KILL_TIMER)
{
QueueFree();
}
}
public void collided(Node body)
{
// If we have !hit something already check if the body we collided with has the 'bullet_hit' method.
// If it does, then call it, passing our global origin as the bullet collision point.
if(hit_something == false)
{
if(body.HasMethod("bullet_hit"))
{
//THIS DOES NOT WORK IN C#, WHAT IS THE ALTERNATIVE?
//body.bullet_hit(BULLET_DAMAGE, GlobalTransform);
// Set hit_something to true because we've hit an object && set free ourself.
}
}
hit_something = true;
QueueFree();
}
}