How to avoid node spiralling out when rotating node around point in a circle via translate()/move()

Elf_EarsElf_Ears Posts: 36Member
edited December 2016 in 2D

When I rotate an object around a point via translate() using
get_node("INSERT_NODE_HERE").translate(Vector2(-1,0).rotated(get_node("INSERT_NODE_HERE").get_global_pos().angle_to_point("INSERT_POINT_HERE"))*speed*delta)
the node rotates around the point in a circle, but it also begins to spiral out from the center, is there any way to fix this?

Here is a gif of my problem
imgur.com/zKoq232

EDIT: This also happens with move() with KinematicBody2D

Answers

  • PaulMurrayPaulMurray Posts: 22Member

    Just a guess but is translate(Vector2(-1,0) being applied every frame, causing the location to spiral out?

  • Elf_EarsElf_Ears Posts: 36Member

    @PaulMurray said:
    Just a guess but is translate(Vector2(-1,0) being applied every frame, causing the location to spiral out?

    yes, it's in _fixed_process(delta), is there some reason that this causes the problem?
    will test with KinematicBody2D to see if it also happens with that...

  • Elf_EarsElf_Ears Posts: 36Member

    can confirm KinematicBody2D has this problem with move()
    (will add to OP)

  • joelnsjoelns Posts: 1Member
    edited December 2016 Answer ✓

    Well, looking at your code, I suppose you are rotating a object by moving it, every frame, a little amount in a direction perpendicular to the line connecting that object to a point. This won't result in a perfect circular movement because, according to the pythagorean theorem, the new distance to the point will be slightly bigger than the previous one:
    [(new distance)²=(old distance)² + (dX)²]
    I think way to fix that is just making the object follow circular path centered on the point

  • Elf_EarsElf_Ears Posts: 36Member

    @joelns said:
    Well, looking at your code, I suppose you are rotating a object by moving it, every frame, a little amount in a direction perpendicular to the line connecting that object to a point. This won't result in a perfect circular movement because, according to the pythagorean theorem, the new distance to the point will be slightly bigger than the previous one:
    [(new distance)²=(old distance)² + (dX)²]
    I think way to fix that is just making the object follow circular path centered on the point

    Yeah, I'd say that would probably be the best hassle free way to do this, thanks!

Sign In or Register to comment.