To start, I'm not working with an engine and am looking for some help fixing the math behind the function I created.
Say we have anchor
, obj
, speed
, dt
, and terminationDist
; function anchorPull
will theoretically pull obj
towards anchor
at a rate of speed
pixels per second until the distance from anchor
to obj
is less than terminationDist
. My implementation is as follows:
def anchorPull(anchor, obj, speed, dt, termDist = 10):
if dist(anchor, obj) > termDist:
deltaX1 = obj.x - anchor.x
deltaY1 = obj.y - anchor.y
theta = degrees(atan(deltaX1/deltaY1))
deltaX2 = sin(theta) * speed * dt
deltaY2 = cos(theta) * speed * dt
obj.x += deltaX2
obj.y += deltaY2
The problem is, at low framerates (a high dt
) obj
wont go all the way to anchor
:
obj
will also stochastically move around when anchor
isn't stationary.
Any help would be great, thanks!