Advertisement

Stop objects and clear all forces

Started by July 14, 2014 03:47 PM
8 comments, last by Ashaman73 10 years, 7 months ago

I have objects that are sliding on a tilt plane (under teh angle of 30°). When they reach the end of the plane, I would like to clear all forces and let objects fall directly down with only gravity affecting them.

Currently, all my objects continue to move in a direction of plane´s tilt and are "slowly" pushed down by gravity (the speed of push down depends on objects speed and mass).

How to achieve such a behaviour ? And is it even possible ?

Thanks


my objects continue to move in a direction of plane´s tilt and are "slowly" pushed down by gravity (the speed of push down depends on objects speed and mass).

That's how it should work, except the "push down" doesn't depend on speed. Force = mass * gravitational_constant. They continue in the direction of the plane's tilt because they have horizontal and vertical speed built up from sliding down the ramp. If there's no horizontal force acting on them after they fall off the end of the ramp, they will continue in the horizontal direction at the same speed. The vertical speed will increase as gravity accelerates the object.

If you just want them to "fall off" the edge unrealistically, detect when the object's position is just beyond the edge of the plane and set the object's horizontal and vertical speeds to 0. If you've got things setup correctly, then, at that point, gravity will be the only force.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Advertisement

There is a problem with this approach, how to find out, that objects is no longer above the plane and should fall. If I hard-code some conditions, it wont work universally. Also, setting velocity to 0 must be done only once - how to find out when - and not continuously (it deactivate gravity).

You can put an invisible vertical plane just beyond the end of the ramp. That will zero the horizontal speed, but not the vertical. For that you can put a short horizontal plane at the end of the ramp.

I.e., final configuration: ramp, short horizontal plane, gap, vertical plane.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

You'll have to pardon my ignorance with bullet, but in Box2d you could do a check to see if the objects are in contact with the ramp, and if they aren't remove all but the downward force. You might have to do a little fudging to only have this occur if the objects are under a certain value, so that if they bounce up off the ramp before hand they don't suddenly stop moving in any other direction.

Doing the invisible plane thing might work, but you'd definitely see a bounce if anything was sliding fast. (for slow objects, it probably is fine.)

Well.. I have tried to find out something that indicats, that objects are in contact with something, but found nothing.

Advertisement

Well.. I have tried to find out something that indicats, that objects are in contact with something, but found nothing.

Does this help? http://www.bulletphysics.org/mediawiki-1.5.8/index.php?title=Collision_Callbacks_and_Triggers

Well.. sort of :-) I will have to add some other info to my SceneObject and with that it should work. Thanks for now

EDIT: Ok.. I have condition and succesfully tested if objects left the plane. But calling clearForces has no effect. How to do it other way?

you should consider friction. Only force that aplies over your objects all the time (in your scenario) is gravitation atraction force, AND, friction eliminating force.

If your object seem to slide at extreme speed resulting in unrealisticc platform donated outer propagation, you are making your object slide a 30 degrees perfect ice smotth platform. (I have crashed my head at such a thing as little brat)

Results are rather strange efect.

If you were free falling towards a point, and colapssed a ground before it with a perfect friction, you would propagete to the pont with same speed still!- thus creating extreme advenced aside movement! (creating an impossible result even physicaly, but phenomenaly existing)

see friction in bullet, straightly compared to weight, tendence and potential


But calling clearForces has no effect. How to do it other way?

You need to do two things:

1. Detect that you dont hit the ground any longer:

Either check contacts or use raytests. Bullet supports contact manifolds and ray casting. To avoid some miss-behavior for bouncing objects, I would check the last 2 frames, that is, you have ground contact only if you detect a contact this and in the last frame.

2. Nullifying the forces is only one part, you still need to clear the current velocity, thought you can keep the up-down (y-axis) velocity.

This topic is closed to new replies.

Advertisement