Making one body push another using physics

Hello guys,
Please take a look to this bg
I need the box to push or apply a force on the sphere on the box movement direction.
How can I achieve that ?
Why is the box passing through the sphere instead pushing it?
Finally:
What is the line:

    boxAggregate.body.disablePreStep = false;

for ? it is not clear for me after reading docs.
Regards.

@Leandro_Roggerone I commented out the animation code and instead applied a linear velocity to the box: https://playground.babylonjs.com/#NQPCYI#1

I believe you have to do operations on the PhysicsAggregate.body instead of the Mesh.position to get the results you want in the physics world

1 Like

Use

    mesh.physicsBody.setPrestepType(BABYLON.PhysicsPrestepType.ACTION)

Here’s an example of a character controller I’m working on, using gltf exported animations to interact with physics.

https://character-7vo.pages.dev

4 Likes

What a great demo! I hope you can share it in Demos and Projects soon. I have a lot of questions like how you made the ramp movement so smooth and how the platforms carry the player horizontally :slight_smile:

1 Like

That is amazing! I had fun for a while just exploring the environment and jumping on platforms. Is it open source?

When the character moves on a slope, an upward or downward force is added according to the velocity direction and slope angle, allowing for smooth horizontal movement.

If the slope exceeds the maximum allowed angle, the character receives a force that pushes it away from the slope to reduce friction, as well as a greater gravity force to make it slide down.

For moving platforms, the player’s velocity is calculated in the platform’s velocity space and then converted back to world space.

The implementation of this character controller has many more details, such as jump input buffering, double jumping, coyote time, some aerial control abilities, and inertia parameters. I won’t be able to fully explain it for now.

4 Likes

Yes, he “will” be open source. But I’m not ready for that yet. There are some bugs, no English comments (I use Chinese). He’s being developed in a non-open source project, which needs to be spun off.

2 Likes