Change of direction in circular movement

I am trying to make character constantly move in circle. If the mouse is clicked, it should change direction, but stay on the same path; it should stay in same radius.

I don’t know how to change the angle of movement to be the opposite. I am using sin and cos to set up the angles.

I think you need to reverse the value of the number in the ToRad() so it’s decreasing. I’m not at my PC to test it. So, I can’t test any ideas.

IDK if it’s a matter of making it negative or subtracting it from another number.

If it’s going in a circle, I might use the place object around a position instead. It uses distance and angle from a point. You could then increase/decrease a variable tied to it.

I tried reversing value in ToRad() but that makes it move in “8” shape. So I think that I should subtract it from another number, not sure which number though.

The reason why I didn’t go for Place around position is because doing it with math seems like the movement is a little bit smoother. But, if I can’t make it work with math I will go for Place around the position option.

I’ll be on my PC eventually.

My thought is when going backwards you could save the current time value you’re using although I don’t know about the transition back to the other direction. Maybe save it before each change and then either add or subtract. IDK. I’m just guessing.

A figure 8 you say. I wonder if you were missing one of the ToRad values. Again, I’d love to test it myself.

As far as smootness, I wonder if you need to use TimeDelta() when increasing/decreasing the variable.

https://wiki.gdevelop.io/gdevelop5/events#timedelta

For the life of me, I can’t figure out how to rework your formula. This works for me.

IDK how it’ll behave with a lot of other code. Although, TimeDelta() is supposed to compensate for irregular timing.

Did you try this extension?
There is an example linked in the description that seems to be exactly what you are trying to do.
https://wiki.gdevelop.io/gdevelop5/extensions/ellipse-movement/reference

This doesn’t work for me, player is teleported to opposite position on every click instead of just changing direction from it’s current position.

This doesn’t make the player stay on the same trajectory as well, every click makes it move in “8” shape.

EDIT: I’ve checked out your Turret movement extension and it’s pretty much what I need. However, I don’t know how to change the values of speed since its moving a bit too fast and deceleration takes too much time to fully stop the object.

I understand that I need to use:

Object.Behavior::PropertySpeedMax()

But how do I do that in the editor?

EDIT2: Figured it out.

Thank you for the help, and thank you @Keith_1357 as well.

1 Like