# How do I get velocityY before a collision happens?

Get help using Construct 2

### » Fri Oct 02, 2015 10:52 pm

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!
B
18
S
7
G
1
Posts: 161
Reputation: 1,941

### » Sat Oct 03, 2015 12:31 am

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!
B
71
S
25
G
20
Posts: 1,759
Reputation: 18,250

### » Sat Oct 03, 2015 6:25 am

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.

Take a look at my itch.io games
B
45
S
14
G
3
Posts: 167
Reputation: 5,204

### » Sat Oct 03, 2015 10:24 am

@Silverforce sounds good, but I want to create different surfaces to lower velocity or increase it, so static height won't help in that case...
B
18
S
7
G
1
Posts: 161
Reputation: 1,941

### » Sat Oct 03, 2015 12:18 pm

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.
B
71
S
25
G
20
Posts: 1,759
Reputation: 18,250

### » Sun Oct 11, 2015 3:44 pm

@Silverforce - 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!
B
18
S
7
G
1
Posts: 161
Reputation: 1,941