Precise stopping

0 favourites
  • 4 posts
From the Asset Store
Create large maps with dynamic depth and precise sprite layering control in top-down games.
  • Hi

    I need a character that uses either the platform behavior or Bullet Behavior to stop precisely when it's x position lines up with that of the object it's overlapping.Does anyone know how I can achieve this?, just testing if the objects x positions are the same doesn't work.

    any help would be appreciated

    thanks

  • Simply texting for the x position to be the same is unlikely to work because Construct can only test an object's position so many times per tick and moves objects multiple pixels at once.

    I see two main solutions for this.

    Probably the more elegant one is to, once it's overlapping, predict when it's going to cross the next tick using dt (there's more information on that if you search the manual). dt times its speed X vector will give you the number of pixels it will move on the next tick. With this you can then test it's approach from the left side using if ((stopper.X - bullet.X) < (bullet.VectorX*dt) and stopper.X > bullet.X), with another modified expression for if the object is approaching from the other side (stopper.X < bullet.X). If true you then set its speed to 0 and use set X to put it in exactly the right place.

    If you're really not comfortable with expressions (though I suggest you do get comfortable with them at some point), another solution would be to create two new invisible objects 1 pixel wide that mark the left and right sides of the stopping object. When the bullet collides with the invisible objects with the correct trajectory (VectorX < 0 for the left one and VectorX > 0 for the second one) you then force the bullet into the precise position (with set position X) and set its speed to 0.

    I hope this helps!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I myself just use 'compare two values', with value one the distance between the player and the object, then check if it is less then a really small number (I use 4 and it will consistently detect, but it may need to be larger if your objects move fast/are large).

    And that's it! There is no way my eyes could ever tell that the player is 1-3 pixels off centre, but if it really matters, make the first action 'set player position to object'. So this way, when it gets within 4 pixels, the player will centre itself on the object.

  • I second tobye suggestion. check for "greater than or equal to" and then snap it back to exactly where you want it right afterwards with a "set position" action, visually you shouldn't see that pop.

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