# Figure 8 Movement

Posts: 2Unconfirmed Member
in 2D

Hello,

First time poster and kinda new to Godot. I'm trying to figure out a figure eight hovering pattern. Current setup is a KinematicBody2D node using the below code snippet to move around a point. However, it seems to drift off and I haven't been able to figure out why. Any insight would be helpful.

I did try running a search on this topic prior to posting with little success. Are there other ways I could try achieving this effect that would be more effective?

Also please let me know if I need to format the code a certain way. I didn't see anything mentioning it but I may have missed something.

``````    velocity = Vector2.ZERO

angle += delta

if angle > 2*PI:
angle = 0

velocity.x = cos(angle)
velocity.y = pow(cos(angle), 2) - pow(sin(angle), 2)
``````

Thanks,

Lina

• Posts: 1,430Moderator

Hi Lina and welcome to the forum! Your post was stuck in the moderation queue, but I've approved it. Please confirm your account with the email we sent you so you can post freely in the future. Thanks.

• Posts: 1,430Moderator

Seems to work alright for me:

``````extends KinematicBody2D

var angle = 0
var velocity = Vector2()

func _process(delta):
velocity = Vector2.ZERO
angle += delta
if angle > 2*PI:
angle = 0
velocity.x = cos(angle)
velocity.y = pow(cos(angle), 2) - pow(sin(angle), 2)

translate(velocity)
``````

You can also look into path following as another option.

https://kidscancode.org/godot_recipes/ai/path_follow/