|
|
|
|
Reply From: |
Kamil Lewan |
First you need to declare circular movement. Like:
EDITED:
var speed = 1
var CircularMovement = Curve2D.new()
var r = 100
var pos = Vector2(200,200)
CircularMovement.add_point(pos+Vector2(r,0),Vector2(0,-r))
CircularMovement.add_point(pos+Vector2(0,r),Vector2(r,0))
CircularMovement.add_point(pos+Vector2(-r,0),Vector2(0,r))
CircularMovement.add_point(pos+Vector2(0,-r),Vector2(-r,0))
CircularMovement.add_point(pos+Vector2(r,0),Vector2(0,-r))
CircularMovement.set_bake_interval(1)
Then you should save somewhere position in baked_points, eg.:
var bppos = 0
If you can use move_to()
instead of move()
, everything will be easier. If so, use:
func _fixed_process(delta):
if bppos + delta*speed >= CircularMovement.get_baked_points().size():
bppos += delta*speed - CircularMovement.get_baked_points().size()
else:
KinematicBody2D.move_pos(CircularMovement.get_baked_points()[round(bppos)])
bppos += delta*speed
SHOULD work, but not best solution.
This is bad due to ignoring the delta value of the fixed process function.
timoschwarzer | 2017-07-12 23:47
Yup, that’s true. It should be something like this:
KinematicBody2D.move_pos(CircularMovement.get_baked_points()[round(bppos)])
bppos += delta*1
And o/c condition: if bppos is at the end of curve; then pbpos = 0
Thanks for caution
Kamil Lewan | 2017-07-13 10:39
Thanks for editing! Now this should work find on any computer / framerate.
timoschwarzer | 2017-07-13 10:56
Many thanks I will try it
pasuva | 2017-07-17 07:47
Hey, thanks! That was really helpful
Do you know how can I change the points to get an elliptical orbit instead of a circular one?
hiulit | 2019-04-18 14:13