![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | sxkod |
Hi All
I have a world that has an AI patrol agent that fires a projectile when it sees the player. I will include the scene trees and code. I can’t seem to figure out why my projectiles go in every direction except towards player
If I need to put the entire project [not that big] I can do that too but I think it is some stupid mistake that can easily be spotted with experience.
projectile code:
extends KinematicBody
var target
func _process(delta):
var ldir=target.global_transform.origin
look_at(ldir, Vector3(0,1,0))
move_and_slide(Vector3(0,0,1), Vector3(0,1,0))
agpatrol [the AI agent that instances the projectile and sets the target]
func _fire_at_ply():
#create a projectile, set it's target. Now the projectile has to do it's own stuff
if dbg_vuln>200 and ctarget:
dbg_vuln=0
dbg_fired=true
var pi=load("res://projectile.tscn").instance()
get_parent().add_child(pi)
pi.set_owner(get_parent())
pi.global_transform.origin=agp.global_transform.origin+Vector3(0,-2,0)
pi.target=ctarget
I added the scene trees here on imgur
Thanks everybody
Have a great weekend