0 Favourites

Physics object velocity

This forum is currently in read-only mode.
  • I have a feeling this is simple.

    How do I get the velocity of a physics object based on the X & Y velocity?

    Values should not be negative.

  • The abs() expression will remove the sign from a number (eg: the positive number only).

    So the X and Y velocity of an object "Object" is:

    abs(Object[Physics].VelocityX)

    and

    abs(Object[Physics].VelocityY)

    However, if you'd like the speed in a single value, you can get that as

    sqrt(Object[Physics].VelocityX ^ 2 + Object[Physics].VelocityY ^ 2)

  • Thank you.

    I acctually used

    float(right(str(Sprite[Physics].Velocityy), len(str(Sprite[Physics].Velocityy))-1))

    Or similar when value was lower than zero, to remove the minus sign. You helpred me a great deal.

  • Thank you.

    I acctually used

    float(right(str(Sprite[Physics].Velocityy), len(str(Sprite[Physics].Velocityy))-1))

    Or similar when value was lower than zero, to remove the minus sign. You helpred me a great deal.

    No problem, if you ever need to do it and the abs() expression isn't there, you can also multiply it by -1 when it's below 0.

  • Is there a way of getting the velocity inside a "for each object" select (So it gets the velocity of only 1 instance)?

    It seems to always only get the velocity of one of the objects. I set a instance variable to velocityX+VelocityY. It's setting another instance variable correctly, so I know that's not the problem.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • I also had that problem. Picking the UID is a solution, but the UID can change by deleting/adding objects. My method was the following:

    I created a global variable(counter) and a private variable ID for the object. Now I add to the foreach action: add 1 to global('counter') and set object('ID') to global('counter').

    So it creates the object, and increases the counter everytime when the sprite is created and assigns the number to the ID.

    Short: every object has its own number in its private variable <img src="smileys/smiley2.gif" border="0" align="middle" />

    You only have to put on the conditions: object('ID') = 2. If you want to make something with the 2nd object.

    It was a little hard for me, to explain it in english. So if you don't understand anything, just reply.

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