How to get inertia without physics?

0 favourites
  • 5 posts
From the Asset Store
In this template the music plays without looping in your game
  • Imagine this: an automatic sniper scope [in form of a cross on the screen] is following the moving object [platform]. The scope is getting closer to it and in given time it will reach the object and shot can be fired. This can be achieved by simple decreasing the distance in relation to moving object. But how to apply inertia to it, when the object decides to suddenly change direction? The preferable result would be that scope will still continue to follow the previous direction of objects movement for a short time and then again follow the object while reducing the distance.

    In other words - the object and the scope are connected by invisible rubber band which shortens in given time...

    Is it possible to achieve this without using the physics?

  • I believe you can do this with MoveTo behavior - set something like speed=200, acceleration=100, deceleration=50. And on every tick move the scope to the object position.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks for the answer, but MoveTo has one flaw. When the object is moving, its coordinates are changing every tick and MoveTo will never reach the object if it runs constantly.

  • You mentioned a rubber band so you could do that with a damped spring. Basically add two variables for xy velocity: vx,vy. Then do the following. You can tune it by changing the 0.005 and 0.1 values. You can use any value from 0 to 1. The first value is the strength of the spring and the second is the amount of damping to apply.

    Compare: dt > 0

    -- add -0.005*(scope.x-target.x)/dt-0.1*vx to vx

    -- add -0.005*(scope.y-target.y)/dt-0.1*vy to vy

    -- scope: set position to (scope.x+vx*dt, scope.y+vy*dt)

  • R0J0hound Still if the target moves slowly, the scope will be lagging behind and never reach it. I tried to make a sort of predictable aim - position the scope slightly in front of the target - but couldn't make it right.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)