Remove elastic when free fall

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
PhilipArthurMoore
Posts: 11
Joined: Sat Oct 13, 2018 1:40 am

Remove elastic when free fall

Post by PhilipArthurMoore » Fri Oct 26, 2018 10:31 am

hello,
i have a box entity, it free fall,
but when it collision with land, position still always change a little
i set bounciness = 0 for both box and land, but i think it still have elastic
how to remove elastic when free fall? how to position dont change when collision land?
thanks

Code: Select all

Space.ForceUpdater.Gravity = new Vector3(0, -10f, 0);

var box = new Box(new Vector(0, 5, 0), 0.5f, 0.5f, 0.5f, 1);
box.Material = new BEPUphysics.Materials.Material(1, 1, 0);       
Space.Add(box);
 
var ground = new Box(new Vector3(0, -0.5f, 0f), 100, 1, 100, 1);
ground.BecomeKinematic();
ground.Material = new BEPUphysics.Materials.Material(1, 1, 0);
Space.Add(ground);

 public override void Update(float dt)
 {
            oldPos3 = box.Position;

            base.Update(dt);

            if (oldPos3 != box.Position)
                Console.WriteLine(" oldPos3:" + oldPos3 + " box.Position:" + box.Position + " box.LinearVelocity:" + box.LinearVelocity);
 }
Console.WriteLine(" oldPos3:" + oldPos3 + " box.Position:" + box.Position + " box.LinearVelocity:" + box.LinearVelocity) always print to console

Norbo
Site Admin
Posts: 4556
Joined: Tue Jul 04, 2006 4:45 am

Re: Remove elastic when free fall

Post by Norbo » Sat Oct 27, 2018 1:44 am

The remaining elastic effect is caused by penetration correction. You can adjust its speed in the CollisionResponseSettings, but if you eliminate it entirely it means that objects won't separate from deep penetration.

Other options include a) enable continuous collision detection (entity.PositionUpdateMode in v1) or b) use a shorter time step so that less penetration occurs between time steps. Neither will eliminate the effect completely in all cases, but it can be significantly reduced.

(v2 note: v2 pushes the use of speculative contacts further than in v1 so this issue is less prominent.)

PhilipArthurMoore
Posts: 11
Joined: Sat Oct 13, 2018 1:40 am

Re: Remove elastic when free fall

Post by PhilipArthurMoore » Sat Oct 27, 2018 3:46 am

Thanks Norbo,
i met the below problem:
if i set box is free fall, i get cases:
if box set bounciness is 0, land set bounciness is 0, it dont have elastic beween box and land when box collission land
if box set bounciness is 1, land set bounciness is 1, it have elastic a little between box and land when box collission land

BUT

if i set box is move to right or left in the air, i get cases:
if box set bounciness is 0, wall set bounciness is 0, it have elastic beween box and wall when box collission wall, and box is move back forever
if box set bounciness is 1, land set bounciness is 1, it dont have elastic between box and wall when box collission wall, box is not moving

Code: Select all

bool freeFall = true;

	box = new Box(new Vector3(0,0, 5), 0.5f, 0.5f, 0.5f, 0.1f);
	box.Material = new BEPUphysics.Materials.Material(100, 100, 0);
	if(!freeFall)
	{
		box.LinearVelocity = new Vector3(6, 0, 0);
		box.Gravity = Vector3.Zero;
	}
            box.Tag = "box";
            Space.Add(box);

            var gWidth = 50;
            var gHeight = 50;
            var ground = new Box(new Vector3(0, 0, -0.5f), gWidth, gHeight, 1, 1);
            ground.BecomeKinematic();
            ground.Material = new BEPUphysics.Materials.Material(100, 100, 0);
            ground.Tag = "ground";
            Space.Add(ground);
            game.Camera.Position = new Vector3(0, -20, 3);

            for (int k = 0; k < 4; k++)
            {
                var wall = new Box(new Vector3(k <= 1 ? (-(gWidth * 0.5f + 0.5f) + (gWidth + 1) * k) : 0, k <= 1 ? 0f : (-(gHeight * 0.5f + 0.5f) + (gHeight + 1) 		* (k - 2)), 50f), k <= 1 ? 1 : gWidth, k <= 1 ? gHeight : 1, 100f, 10f);
                wall.BecomeKinematic();
                wall.Tag = "wall";
                wall.Material = new BEPUphysics.Materials.Material(100, 100, 0);
                Space.Add(wall);
            }

Norbo
Site Admin
Posts: 4556
Joined: Tue Jul 04, 2006 4:45 am

Re: Remove elastic when free fall

Post by Norbo » Sat Oct 27, 2018 4:19 am

Sorry, I'm not sure what you're asking about. All material combinations work as expected in the provided code snippet when run in the BEPUphysicsDemos.

If you're asking about how the bounciness of two bodies interacts to create the collision response, the material property of each body is combined using the MaterialManager.MaterialBlender. This defaults to the MaterialManager.DefaultMaterialBlender function which uses multiplicative blending. So, if one body has a bounciness of 1 and the other body has a bounciness of 0, the resulting pair bounciness is 1 * 0 = 0. You can supply your own function if you want.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests