Physics Velocity

0 favourites
  • 7 posts
From the Asset Store
Simple yet very life-like rag doll made with Physics!
  • Hi, I'm having a lot of trouble with this problem:

    I have a spaceship and a variable called 'velocity threshold' - I want it so that if the ships velocity is past the threshold and the ship collides with a wall, the ship should blow up.

    The ship can move in 360 degrees, like asteroids.

    Any help is appreciated, thanks

  • You can calculate the total velocity of an object with the physics behavior with:

    sqrt(sprite.physics.VelocityX^2+sprite.physics.VelocityY^2)

    Then compare that with your 'velocity threshold' with a 'on collison' trigger.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Another alternative (which I usually use) is distance(0,0,sprite.physics.velocityX,sprite.physics.velocityY)

  • You can get the X and Y velocity using   ship.physics.velocityX/Y

    so to find the overall velocity in any direction, is like trying to find the longest side of a triangle with pythagoras' theorem

    Imagine 'a' is velocityX and 'b' is velocityY.. the overall velocity would be 'c'

    Here's the full page

    so to get the overall velocity in any direction, it's:

    sqrt(ship.physics.velocityX^2,ship.physics.velocityY^2)

    you might have to put each velocity value inside an abs( ) to avoid negative numbers but i'm not sure.

    there is an easier way though..

    The distance() expression uses pythagoras in the same way, so you can actually just use that..

    distance(0,0,ship.physics.velocityX,ship.physics.velocityY)

    if you do it this way, I just figured it'd be good to know why it works first

    edit: double ninja'd, i aint even mad

  • "edit: double ninja'd, i aint even mad"

    LOL <img src="smileys/smiley1.gif" border="0" align="middle" />

  • Wow thanks, multiple solutions here - got it all working now and I've learnt some new stuff!

  • It was the distance(0,0,ship.physics.velocityX,ship.physics.velocityY) which worked.

    Using sqrt(sprite.physics.VelocityX^2+sprite.physics.VelocityY^2)

    almost worked except for 'head on' collisions which must have been negative values.

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