i cant change velocity

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Ktotoetoia

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)

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?

MateuS | 2022-08-04 08:43

and is raycast colliiding ? Print it to make sure

Inces | 2022-08-03 18:01

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.

jgodfrey | 2022-08-03 18:40

if player in area2d presled = true

Ktotoetoia | 2022-08-04 09:07

:bust_in_silhouette: Reply From: Ktotoetoia

i add

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

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