• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Problem Rotating Sprite + Lerp

P

ProjectGamesInc

Guest
Hi all,

I'm trying to rotate an enemy that is following a path.
using image_angle = direction works but it gives me the "lag" (it dosent change smoothly the angle) effect beacouse the enemy is moving slowly and i have big difference beetween the "past" direction and the "actual" one from step to step.

Then i wrote something like this
image_angle = lerp(image_angle,direction,0.1)
It also work and the image angle change smoothly but, when my enemy it is facing right (or it is near that angle) seems like the sprite do a fast loop the loop and then start again rotate smoothly.

I hope i described the problem well.
Any help about a solution?
Thanks!
 

Phil Strahl

Member
I think that is due to how Game Maker interprets angles, so 360° = 0° and that's "right", so you might have a situation where your enemy lerps between angles of 359 and 1 and thus spins around clockwise. A quick fix might be to just add 360 before lerp, e.g.
Code:
image_angle = lerp(image_angle,direction + 360, 0.1)
 
P

ProjectGamesInc

Guest
I think that is due to how Game Maker interprets angles, so 360° = 0° and that's "right", so you might have a situation where your enemy lerps between angles of 359 and 1 and thus spins around clockwise. A quick fix might be to just add 360 before lerp, e.g.
Code:
image_angle = lerp(image_angle,direction + 360, 0.1)
Hi and thanks for the reply.
I've tryied your solution, but nothing changes, still have the spin.
I'm a little bit confused right now, cant really understand how and where i should fix this.
 
M

Marcus12321

Guest
Hi and thanks for the reply.
I've tryied your solution, but nothing changes, still have the spin.
I'm a little bit confused right now, cant really understand how and where i should fix this.
have you tried adding the 360 to both, th eimage_angle and the direction?

mage_angle = lerp(image_angle+360,direction + 360, 0.1)

I am not sure this will work, but something that jumped out at me.
 
P

ProjectGamesInc

Guest
Does not change, they spin like usual.
Other fun thing, i saw that they do like 3-4 fast full 360 spin when created.

BTW the problem still here, damn.
 

Phil Strahl

Member
Okay, I did a few tests and it seems that image_angle can be greater than 360 and less than 0 and work as intended. However, direction always clamps between 0 and 360.

So my suggestion would be to use your own direction variable, e.g. name it myDirection, and use it for all calculations in your step event and only at the very end assign it like direction = myDirection where it gets clamped.

It's just important that you don't do something like myDirection = direction at the start of each step as that would lead to the same problem you're having.

Below is my little test object's code. Its sprite is a right-facing arrow.

Create
Code:
myDireciton = 0
Step
Code:
var step = 1

if (keyboard_check_direct(vk_shift))
{
   step *= 4
}

if (keyboard_check(vk_left))
{
   myDirection += step
}

if (keyboard_check(vk_right))
{
   myDirection -= step
}

image_angle = lerp(image_angle, myDirection, 0.2)
direction = myDirection
Draw
Code:
draw_self()
draw_set_color(c_white)
draw_text(x,y-80,string(image_angle))
 
Last edited:
Top