Maxspeed for falling object

stray
Posts: 2
Joined: Thu Feb 24, 2011 2:09 pm

Maxspeed for falling object

Post by stray »

Hello all!
I have a little problem with maxspeed for gravity...
You see, this is really simple. I set gravity to -10, and created some BoxShapes.
In Update method i'm taking all collistionObjects from DynamicsWorld and setting Y to orginal height if is larger then value. It works fine, and object appears on the top of another object, but it has his old speed which is growing because of gravity... I have tried to set InterpolationLinearVelocity to vector e.g. 1,1,1 but without luck..

Code: Select all

public virtual void Update(float elapsedTime)
        {
            foreach (CollisionObject collisionObject in World.CollisionObjectArray)
            {
                if (collisionObject.UserObject.ToString() == "ball")
                {
                      //put object on the top of the other object.
                    if (collisionObject.WorldTransform.Translation.Y < -10)
                    {
                        Random rand = new Random();
                        float start_x = rand.Next(-(Convert.ToInt32(Math.Ceiling(wx))), Convert.ToInt32(Math.Ceiling(wx / 2)));
                        Matrix startTransform = Matrix.CreateTranslation(new Vector3(start_x,2 * wy,(float)-2.55));
                        collisionObject.WorldTransform = startTransform;

                    }
                       //Reset speed. Set speed i.e. to 20 or something.... it doesn't work and i don't know why :(
                    //Vector3 maxSpeed = new Vector3(20, 20, 1);
                    //   collisionObject.InterpolationLinearVelocity = maxSpeed;
                   
                } 
            }
            World.StepSimulation(elapsedTime);
        }
It will be great if you could give me an advice... i have spent few hours on this and don't know what to do....

Thanks
winspear
Posts: 77
Joined: Thu Nov 26, 2009 6:32 pm

Re: Maxspeed for falling object

Post by winspear »

Just add some damping to the rigid body to control velocity using setDamping function.
stray
Posts: 2
Joined: Thu Feb 24, 2011 2:09 pm

Re: Maxspeed for falling object

Post by stray »

Thank you!!!
I owe you a beer!
winspear
Posts: 77
Joined: Thu Nov 26, 2009 6:32 pm

Re: Maxspeed for falling object

Post by winspear »

You're welcome. I could use a cold beer right now. :mrgreen: