Physics behavior how to store velocity/direction/speed?

This forum is currently in read-only mode.
  • Hi folks!

    Hope theres atleast some ppl still browsing the classic section...

    Im having issues trying to figure out how to store a sprites velocity in a certain way, ill try and explain the best i can:

    i have a physics object(sprite1) and when it overlaps sprite2, i want sprite1 to slow down a bit, and then when its not overlapping sprite2 anymore, id like the sprite1 to get back its original velocity(what it was before overlapping sprite2), but i just cant figure out how to manage this. i did manage to do this with only using either X or Y velocity, but i have problems when sprite1 is not moving completely horizontally or vertically.

    if theres still anyone out there willing to help id be most grateful.

    sorry bout my poor grammar btw.

    thanks.

  • If it's behaving funny, this is an example of a work-around I did for changing position of a physics object and keeping its speed, maybe something like this could help when trying to change the speed that the object is moving:

    + Object: Object overlaps TeleportA

    + System: Trigger once

    -> Object: Set 'VelocityX' to Object[Physics].VelocityX

    -> Object: Set 'VelocityY' to Object[Physics].VelocityY

    -> Object: Set immovable: Yes

    -> Object: Set position to object TeleportB (image point 0)

    -> Object: Set immovable: No

    -> Object: Set velocity to (Object.Value('VelocityX'), Object.Value('VelocityY'))

    However, I will try to make a cap doing what I think you're looking for when I get some time!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • hi jayjay and thanks for replying!

    ive been on a holiday, so i havent been able to try out what you suggested, but im gonna give that a shot sometime this week. although im not completely sure how to make that work, so if you got the time id still be very interested in seeing some kind of an example .cap!

  • Sure! Here's a Cap <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    https://dl.dropboxusercontent.com/u/471 ... hysics.cap

    The example I made doesn't use gravity, so you may need to tweak the code to counter-act or reduce gravity a bit while overlapping Sprite2 if you want that to slow down as well.

    Hope it helps! <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy">

  • many thanks!

    at first it all looked a little overwhelming, but i think i understand the code (mostly).

    however i still have issues with that gravity thing and to make matters worse(or better?), im planning on not using the gravity (that preset world gravity) of the physics behaviour, but simply use add force, mainly because i want to be able to decide the direction of gravity at will. would it be too complex to implement in this example? if say the gravity was made like,

    -always:

    --add force 175 (y component)

    ?

  • If you want gravity to still have the same pull even inside the Sprite2 region, then I think that might work okay.

    For decreased gravity in the region you can do:

    Not overlapping Sprite2 = add force 175 to Y

    Overlapping Sprite2 = add force 50 to Y instead

    If that doesn't work I will try to think of another way to do it though!

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