[SOLVED] How to move rigidbody(sticked to wall) from one wall to another wall?

I need to move a rigidbody from one wall to another wall, just like a cube, six faces, from one face to another.

I hope that the rigidbody can automatically rotate when it moved the other wall, that means the surface which contact the wall should always contact another wall.

Currently I apply a force to the rigidbody on update function so that it can stick to the wall (one face of a cube). As the cube is a regular shape, I can know which force direction I should apply to the rigidbody. (just (±1,0,0), (0, ±1, 0), (0,0,±1)).

But I want to support custom model. So the stick force direction will be dynamically. How can I calculate the force ?

What’s more, how can I know what the eulerangles should be when the rigidbody move to another wall ?

Thanks.

If I’m understand this correctly, you would be looking at applying a force that is perpendicular to the surface normal. You can do a raycast against a physics shape and the result should give you the normal of the surface that it hits against.

Are you trying to ‘walk’ around a cube/shape like in Super Mario Galaxy?

If I’m understand this correctly, you would be looking at applying a force that is perpendicular to the surface normal. You can do a raycast against a physics shape and the result should give you the normal of the surface that it hits against.

I did the same work. But my implementation is apply a regular force ((±1, 0, 0) or (0, ±1, 0) or (0, 0, ±1)) to the rigidbody, when it contact the wall, its collision trigger contact event, I can get the pointOther from ContactResult. And then raycast to the pointOther, get the wall’s normal. At last, calculate the stick force by pc.Vec3.ZERO.clone().sub(normal).

This is a bit annoying. Is there any better implementation ?

Are you trying to ‘walk’ around a cube/shape like in Super Mario Galaxy?

Yes, exactly. Now I am finding a way to walk on the wall. Like the following:

When walking to the other wall, the rigidbody should change to the right orientation.

Are you walking on the inside of a cube or the outside of one?

Generally, it is inside of a cube.

If it’s inside a cube like the videos above, I would do a raycast on the player’s local down axis and use the surface normal as the direction for ‘gravity’ on what ever it hits and reorient the player based on the gravity direction.

As you can see in video, of Mario, I believe Mario can only transfer from one wall to another using the ramps which are gradually sloped. So as the player moves over the ramp, it should automatically and smoothly transfer.

1 Like

I see.

One more question, as you can see, Mario can move on the walls.
Let’s assume that the player can operate Mario by the keyboard. By pressing W, S, A, D to make Mario move, in other words, when pressing W, S, A, D, we will apply a force to Mario. See the following:

  • On the floor:

    • W: a forward force
    • S: a backward force
    • A: a leftward force
    • D: a rightward force
  • On the left wall:

    • W: a forward force
    • S: a backward force
    • A: a upward force
    • D: a downward force
  • On the back wall:

    • W: a upward force
    • S: a downward force
    • A: a leftward force
    • D: a rightward force

When Mario on different wall, the W, S, A, D should apply different force on him. So, my question is, suppose Mario is in a random shape space with many walls, how to calculate the force ?

Again, I would use the local axes of the player (local forward, back, left, right) rather than the world axes to apply forces to move.

1 Like

How can I implementation this ?

In playcanvas, I just know using entity.rigidbody.applyForce(force) to move the rigidbody…

Something like this for moving forwards.

var forceVec = new pc.Vec3();
forceVec.copy(playerEntity.forward).scale(forceScalar);
playerEntity.rigidbody.applyForce(forceVec);
1 Like

Oh, I see now! Thanks for your help!!