I am trying to make a NPC (KinematicBody (3D) firing a bullet to the direction the NPC is lookingat.
I successfully get my bullets spawning in front of the NPC, but instead of moving along the facing direction, they are always spawing and moving 90° from the lookat direction of the npc.
This is my code of the NPC setting look_at to the players position
(that part works fine so far)
var LookAtPosition = get_node("../Player").get_translation()
var follow_vect = (LookAtPosition-get_translation()).normalized()*delta*speed
My shoot Function is now instancing the bullet scene (KinematicBody Node)
and I set the bullets values to the current NPCs Position & Rotation_Degree
if fire_delay < 0:
var shot = bullet_scene.instance()
shot.global_transform.origin = transform.origin
shot.rotation_degrees = rotation_degrees
fire_delay = max_fire_delay
fire_delay -= 1.0 * delta
In my Bullet Scene I do that:
if ttl < 0:
ttl -= delta
move_and_slide(get_global_transform().basis.x * speed)
As shown on the screen below, the bullets are not spawning and moving on the look_at angle, but 90 degress from the side of the npc.
What's wrong here? I'm importing my objects from blender. Is there a certain rotation to be done to define which part of the object is the front, left and right? Is there a better way to simply say: take the look_at direction as a vector and let another kinematicbody move along that vector?