For a game I'm making I need to pull/push a player object towards/away from static platforms with a magnetic polarity. What's the best way to do this with Box2D, switching gravity or whatever?
How to pull objects towards platform
General DiscussionI think the best way is to apply force to player.
wqyfavor wrote:
I think the best way is to apply force to player.
How would I go about constantly pulling the player to the platform so they can walk around the edges and even upside down though?
I think the best way is set the world gravity to 0 and then create a function with input distance, force and masses of the "platform" and output is the force to apply. Elaborate this function for every platform(or only the nearest, use a spherical sensor around you body to get the platforms) and sum the results: here your actual "gravity".
if you use the gravity function (the real one), platform with bigger mass(in your case powerful magnet) will attract player more than platform with small mass. Also bigger platform will make your player jump less
You can also simply use distance from point, if you want the player be attracted from the nearest platform, without the problem with masses, but this is very unreal movement
if you use the gravity function (the real one), platform with bigger mass(in your case powerful magnet) will attract player more than platform with small mass. Also bigger platform will make your player jump less
You can also simply use distance from point, if you want the player be attracted from the nearest platform, without the problem with masses, but this is very unreal movement
lestofante wrote:
I think the best way is set the world gravity to 0 and then create a function with input distance, force and masses of the "platform" and output is the force to apply. Elaborate this function for every platform(or only the nearest, use a spherical sensor around you body to get the platforms) and sum the results: here your actual "gravity".
if you use the gravity function (the real one), platform with bigger mass(in your case powerful magnet) will attract player more than platform with small mass. Also bigger platform will make your player jump less
You can also simply use distance from point, if you want the player be attracted from the nearest platform, without the problem with masses, but this is very unreal movement
if you use the gravity function (the real one), platform with bigger mass(in your case powerful magnet) will attract player more than platform with small mass. Also bigger platform will make your player jump less
You can also simply use distance from point, if you want the player be attracted from the nearest platform, without the problem with masses, but this is very unreal movement
Ok thanks, anybody else have any other ideas? 🙂
bumpity
I would like to bump this as well.
Is there a way that does not involve the overall gravity?
Is there a way that does not involve the overall gravity?
I am doing exactly this in the game I am currently working on. To start with, I set my world gravity to 0, and apply gravity to all of my objects manually. I use a trigger region (sensor) to detect which objects should be affected by the platform's gravity, and in my level editor I link it to the platform that I want things to be attracted to. On the trigger is an editable property indicating the magnitude of the gravity (I could do this based on mass, but I want to have fine-tuned control over the gravity for each object). When I detect that there is an object in the trigger region, I find the closest point on the platform to the object using b2Distance, and apply the force toward that point. Alternatively, you could just apply gravity toward the center of the object (which is much cheaper than using b2Distance), however in my experience that only works well for circular objects. For objects that are within these regions, I do not apply world gravity. Sometimes I have overlapping gravity regions...in this case I simply average the gravities, which is not physically realistic, but works well enough for my purposes. However you could easily use your own mixing rules for gravity in overlapping regions (such as weight the gravity based on mass, distance to the platform, etc).
Sorry if my explanation is not very good, if you need more info I would be happy to provide it.
Sorry if my explanation is not very good, if you need more info I would be happy to provide it.
here is a flash example (hold shift and roll with a or d)
http://www.sideroller.com/
its made with wck which is open source.
to quote mayobutter (the author of wck and the person who made that sideroller proto-type)
http://www.sideroller.com/
its made with wck which is open source.
to quote mayobutter (the author of wck and the person who made that sideroller proto-type)
Quote:
If you take a look at the experimental "Actor" and "GroundFinder" classes you can see the core of the algorithm. Based on the roll direction (clockwise/counter clockwise) it finds the "ideal" contact for movement, and negates the friction on all other contacts (friction drives movement). This prevents the ball from getting stuck in corners. Sticky mode involves applying a force between the player and that contact, and disabling gravity. If suddenly the player becomes airborne, a corrective force must be applied to get him back to the ground (he actually "hangs" for a frame when rounding corners). It is still buggy in places. For example, at the point between two polygons mocking the outside of a circle, the player will be jerked backwards because it thinks it's rounding a right angle before hitting the next polygon (actually... it just occurred to me some overlap might fix that).
Yes, locate the contact, and thus, the normal of the contact. Apply a force from the player towards the platform. Profit.
Original thread: https://box2d.org/forum/viewtopic.php?t=4655