☑ Dynamic body passing through static bodies

Hi all

I have a simple ground box and walls with collision and a rigbody.
The red box (player) has the same applied to it plus the player-move sript. You can see the sript below.

As you can see in the gif here, sometimes the collision does not work and I have no freakin idea why? It’s a simple setup but it doesn’t work constantly. I have tried a lot, not sure if it’s something in the editor or in the script?
Any ideas?



var DynamicBody = pc.createScript(‘player-move’);

// initialize code called once per entity
DynamicBody.prototype.initialize = function() {
this.torque = 100;
this.app.keyboard.on(pc.EVENT_KEYDOWN, this.onKeyDown, this);

DynamicBody.prototype.onKeyDown = function (event) {

// update code called every frame
DynamicBody.prototype.update = function(dt) {

//update player's position
this.playerPos = this.entity.getLocalPosition();
var app = this.app;
//keyboard controls and applying forces and moments.
if (app.keyboard.isPressed(pc.KEY_UP) ) {
    this.entity.rigidbody.applyImpulse(0, 0, -3);
if (app.keyboard.isPressed(pc.KEY_DOWN) ) {
    this.entity.rigidbody.applyImpulse(0, 0, 3);

// Acceleration
this.entity.rigidbody.applyForce(4, 0, 0); 


This might have to do with the scale of your objects. It’s best to use realistic sizes for your objects and physics as in 1 playcanvas unit = 1 meter. What size are your objects there? Also it’d be useful to have a link to your project.

1 Like

Thanks for your reply!

In the first scene, my objects are far toooo big so I made a scene 2 with realistic scale as you said.
The red box is now 2x1x1


It’s still not working

Have you tried making the collision volumes for the walls fatter? :slight_smile:

There’s no reason they can’t differ in size from the graphics representations.

1 Like

Yep, I have done that before. The collision of the wall is now at 100x 3y 10z to test but it’s still not working. If I press Up Down Keys to move the box… after 3, 4 collision hits the box moves through the wall :fearful:

:heart_eyes: SOLVED! Ok I’m testing right now, looks good :grin:

My ground was a plate with collision y1. Seems that does not work.
Replaced my ground with a same sized box with y1 and collision 1. I hope that was the problem

Yep, I just discovered that too. Congratulations on beating me to report the solution! :slight_smile:

Ok I was to early :disappointed: fell off again! Haha you are in the race again :wink:

Just make the ground even thicker. Try 2, say, or more. Making the ground body thicker definitely made a big difference.

Ground is now at y10 with collision y5. Still does not work. I discovered an engine bug :sweat_smile:
It drives me craaazy :rocket:

OK, here’s another suggestion. With Bullet/Ammo.js (PlayCanvas’ physics engine), it’s generally bad to have very, very big bodies collide with very, very small ones. That’s just how the physics engine works - nothing we can do about it.

Try to have a better level of proportionality.

So either you could:

  • Make the dynamic body larger.
  • Make the environment out of a polygon mesh (constructed in Blender/Maya/3DS Max).
1 Like

Ok thanks I’ll try that :thumbsup: Keep you posted here.

Thanks for your time by the way!

I’m cautious but I think it works now… whit a bigger dynamic body :clap: :clap:
Awesome, thanks so much @will :thumbsup::top:

1 Like

Yay! That’s great. :smile: