0 votes

hi , i'm making an demonic eye ai from terraria, now im making bound mechanic(when eye touch object it change his direction) and i cant change velocity, when i try vel *=-1 or vel.x +=10000 it do nothing

func _physics_process(delta):
var v = player.global_position - global_position
var angle = v.angle()
if $RayCast2D.is_colliding():
    vel *= -1
var r = global_rotation
if presled == true:
    global_rotation = lerp(r,angle,.1)
    vel = global_position.direction_to($looking.global_position) * speed
vel = move_and_slide(vel)
in Engine by (99 points)

and is raycast colliiding ? Print it to make sure

Also, I can't tell what that presled variable is for, but if its value is true, you assign a new value to vel, that doesn't consider any previous value.

Could it be that presled is true and the velocity is changed by vel = global_position.direction_to($looking.global_position) * speed, invalidating the first change of the velocity? What does presled represents?

if player in area2d presled = true

1 Answer

0 votes

i add

if $RayCast2D.is_colliding(): vel *= -1

in the end of code, and it worked
thanks everyone!

by (99 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.