Physics behavior how to store velocity/direction/speed?

For questions about using Classic.

Post » Thu Jul 30, 2015 12:23 am

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.
B
3
S
1
Posts: 11
Reputation: 447

Post » Mon Aug 10, 2015 12:45 am

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!
"Construct 4 lets YOU make advanced games! (but not play them)" Construct Classic - Examples Kit
B
113
S
39
G
17
Posts: 2,183
Reputation: 19,215

Post » Mon Aug 24, 2015 11:32 pm

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!
B
3
S
1
Posts: 11
Reputation: 447

Post » Tue Aug 25, 2015 3:42 pm

Sure! Here's a Cap :)

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! :D
"Construct 4 lets YOU make advanced games! (but not play them)" Construct Classic - Examples Kit
B
113
S
39
G
17
Posts: 2,183
Reputation: 19,215

Post » Tue Aug 25, 2015 9:36 pm

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)

?
B
3
S
1
Posts: 11
Reputation: 447

Post » Wed Aug 26, 2015 3:05 pm

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! :)
"Construct 4 lets YOU make advanced games! (but not play them)" Construct Classic - Examples Kit
B
113
S
39
G
17
Posts: 2,183
Reputation: 19,215


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 0 guests