Physics modifiers based on position

Topics: User Forum
Jan 7, 2011 at 5:33 PM

Hello,

I have been struggling with the best way to accomplish this for a while now. Basically I have a varying portion of the screen covered by lights, and when an object is touched by the lights I want to change the physics properties for that object. So say I find out that if an object is covered by a light, I want to slow down time for that object, or modify the object's friction, but only while the object is in the light.

What I have working so far is being able to tell if the object is touched by a light or not, that's the easy part. But what is the best way to go about changing the object's properties for only the time that contact is occurring? Is it even possible to change the "physics time" for the object to make it faster or slower compared to other objects?

Thanks for any pointers.

Coordinator
Jan 8, 2011 at 5:16 PM

You can change the properties such as friction on the fly. You could create a slow-effect using the drag coefficients. Another way to slow them down would be to use the VelocityLimitController introduced in FPE 3.2, but I'm not sure that is what you are looking for.

Jan 9, 2011 at 7:07 AM
Edited Jan 9, 2011 at 7:13 AM

One method for the slow-motion would be to have 2 engines running. One slow and one normal speed.

When an object falls into light, change its body type to kinematic and create a copy of it in the slow engine.

Then during each frame, update the kinematic bodies positions and velocity to match their slow couterparts. Once it leaves the light remove it from the slow world and change it back to dynamic.

EDIT: Speed note:

dont worry about speed initially. Static bodies dont get updated unless a dynamic body is touching them.
As long as there are only a few dynamic items at a time I doubt you'll notice the difference. 
One method to increase speed though (if its needed) would be to only update the slow engine every second timestep or on a slower thread. 

Jan 11, 2011 at 8:25 PM

In my current project Asteroid Command I use Body.LinearDamping to reduce the speed of the asteroids when they approach the target to allow the player to react before its too late.

I increase the LinearDamping based on the distance to the target so the closer it gets the slower it moves.

This works pretty good for my type of game but this is a top down space game :)

Here is a link of how it works and looks: http://www.casualgames.nu/AsteroidCommand.aspx

 


Jan 11, 2011 at 8:33 PM

Thanks guys, I never even considered the possibility of just creating another instance of an engine to work with! I will try that if I can't get any of the drag and damping and even the Velocitylimit Controller to achieve what I want.