im struggling to add gravity to the enemies in my game. if i jump on a ledge or something that high up they will float towards me without gravity effecting them.
this is what ive tried so far. Sorry for the bad paste of code, no matter what i do here it wont look right, in the editor the indentation is correct.
var target
export var speed = 350
var health = 100
var gravity = -350
var velocity = Vector3()
func physicsprocess(delta):
if target:
lookat(target.globaltransform.origin, Vector3.UP)
movetotarget(delta)
func onrangebodyentered(body):
if body.isingroup("Players"):
target = body
func movetotarget(delta):
velocity.y += gravity * delta
var dir = (target.transform.origin - transform.origin).normalized()
velocity = moveandslide(dir * speed * delta, Vector3.UP)