[SOLVED] Weird behaviour when applying force to entity with rigidbody

I’m trying to add force via:

this.force.set (100, 0, 0);//.normalize ();
this.player.rigidbody.applyForce (this.force);

The player should move to the left but my player just tilts to the left and falls through the floor.

The force is applied when you touch the left side of the screen and move your finger(I haven’t tested this on a PC)



I’ve used a lot of files from the tutorials. The important code should only be in index.html and touch-input.js

If the player falls through the floor, add a collision and static rigidbody to the floor. Also, turn of all the angular factors on the player’s rigidbody.

There is a collision box on both the player and the ground along with dynamic rigidbody on player and static on ground. I have turned off angular factor and now it has stopped tilting but it still goes through the ground.(I haven’t updated this on the demo yet.)

Can I see the project in the editor?

I’m not using the editor. I’m writing the code myself and the entire project is on GitHub(linked above). I’m not sure but maybe you can import it into the editor but I haven’t tried that.

@Gamer_Wael has the Github source been updated?

Why are the half extents for the floor 0?

ground.addComponent('collision', {
            type: 'box',
            halfExtents: [0,0,0],

I changed the halfextents size in the console:

var root = pc.app.root
root.children[1].collision.halfExtents = new pc.Vec3(20, 0.01, 20)

And now it works as it should.

You can see here where I render the collision shapes in the viewport:

1 Like

I’ve updated the source but the demo doesn’t seem to have updated yet. My touch-input.js is very messy right now and I am planning to rewrite the entire thing so please don’t mind that. The only important line in touch input should be lines 120-121

this.force.set (100, 0, 0);//.normalize ();
this.player.rigidbody.applyForce (this.force);

One thing to note is that my rigid body halfExtents for the ground are [0,0,0]. My player falls and stops on the ground and when I apply force it falls through. I tried increasing halfExtents but it had no effect.

See my post above. I’ve changed the half extents to be a decent size and it works fine in my case.

No dimension of the collision should be 0.

1 Like

Ah right. Thanks a lot. I was only increasing halfextent by a very small amout which is why I didn’t notice it.