Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | King C rocodile |
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 _physics_process(delta):
if target:
look_at(target.global_transform.origin, Vector3.UP)
move_to_target(delta)
func _on_range_body_entered(body):
if body.is_in_group(“Players”):
target = body
func move_to_target(delta):
velocity.y += gravity * delta
var dir = (target.transform.origin - transform.origin).normalized()
velocity = move_and_slide(dir * speed * delta, Vector3.UP)