Godot Engine

Godot Engine

MagicFool Mar 29, 2020 @ 2:22pm
Change sprite according to mouse direction
I'm trying to make a game where the character's sprite changes according to mouse direction. There are 4 directions for the characters. Do you know which script I need?
< >
Showing 1-1 of 1 comments
Matt [Linux] Mar 29, 2020 @ 3:09pm 
you need to find the angle between the sprite and the mouse each frame using ...

https://docs.godotengine.org/en/3.1/classes/class_vector2.html#class-vector2-method-angle-to

you might wanna change the angle value returned from that funnction to Degrees using...

http://docs.godotengine.org/en/latest/classes/class_@gdscript.html?highlight=rad2deg#class-gdscript-method-rad2deg

then use that angle value to choose which sprite to set...

if angle > 45 and angle < 134:
sprite.set_texture(texUP)
elif angle >= 135 and angle < 224:
sprite.set_texture(texLEFT)
elif angle >= 225 and angle < 314:
sprite.set_texture(texDOWN)
elif angle >= 315 and angle <= 360:
sprite.set_texture(texRIGHT)
elif angle >= 0 and angle <=44
sprite.set_texture(texRIGHT)
Last edited by Matt [Linux]; Mar 29, 2020 @ 3:12pm
< >
Showing 1-1 of 1 comments
Per page: 1530 50

Date Posted: Mar 29, 2020 @ 2:22pm
Posts: 1