How do I get velocityY before a collision happens?

  • Hello all,

    I have this capx:

    http://www.fast-files.com/getfile.aspx?file=98323

    Basically this is a spaceship that moves by inertia using the up left and right keys.

    Upon hitting the floor, I want to damage the ship according to its velocityY meaning falling for a higher place will cause more damage.

    When I print out the HitVelocity inside the "on collision" event, I get the VelocityY AFTER the impact, so it shows much lesser damage...

    How can I calculate the damage needed BEFORE the impact?

    Thanks!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You call that after On Collision so it will always be after the impact has already occurred.

    If you want the ship's velocity just before impact, you need to have a separate event that tracks the distance of your ship to the floor.

    Use the test two value,

    distance(Ship.X, Ship.Y, Floor.X, Floor.Y)

    Less than 100 (or whatever pixel distance you need for it to work).

    Then set the variable HitVelocity then. Before impact.

    That should work, good luck!

  • I've never really used this so it's only theoretical, but couldn't you just use a variable for velocityY that updates at the end of the tick? Then it will always be the tick before the collision. I can't tell if this is what Silverforce is suggesting, but it may work.

  • sounds good, but I want to create different surfaces to lower velocity or increase it, so static height won't help in that case...

  • You can work around it by having an invisible line that acts as the pre-collide check. The line can have an instance variable to define what it is (so you can change velocity as you wish).

    Then do a collision check for that line, filter the instance variable, record the velocity etc.

    This always trigger before the real collision.

    It's a work-around but it will work to damage base on velocity before impact.

  • - nice workaround, though I suspect that in lower frame rate situation the ship could pass by this line?

    Then again - THAT low of a frame rate means the game is unplayable

    Thanks!

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