Third Person Controller-BUG

I used a simple third person controller to control the walking of the character. When I created a rigid body in the scene and dragged the mouse to rotate the camera, there was a problem of passing through the mold. The character would pass through the mold, and the entity would also pass through the mold. Why is this? How can I solve this problem? It has been bothering me for a long time. Can someone help me solve this problem? I don’t know how to write this code




https://playcanvas.com/project/1309756/overview/third-person-controller

Why is my post inactive and not followed by anyone

Hi @Guohao6666!

I’m afraid you can’t really solve this when the camera goes into a model.

You can improve it slightly by changing the Near Clip of the camera component from 0.3 to 0.01.


I placed a model of an indoor scene and added rigid bodies to it. When my character is far from the wall, especially when going up stairs and corners, the model will be worn. If I change the texture ball to display on both sides, then the character will not be visible

I had similar issues in my game. It wasn’t easy to solve. I ended up creating a custom camera controller to adjust the camera distance based on obstacles in the scene.

Before:

After:

Thank you very much for your answer. Can you share a case study? This problem has been solved for a long time

In your example, you could add the hit normal to the point so there is a margin instead of being exactly on the model.
You can change the function below to get the result.

CameraMovement.prototype.getWorldPoint = function () {
    var from = this.entity.parent.getPosition(); 
    var to = this.rayEnd.getPosition();

    var hitPoint = to;

    var app = this.app;
    var hit = app.systems.rigidbody.raycastFirst(from, to);

    var marginLength = 0.25; // Variable that changes the length of the margin
    // Adds the normal to the point so it isn't exactly on the model
    return hit ? hit.point.clone().add(hit.normal.clone().mulScalar(marginLength)) : to;
};

Hope this is what you were looking for!

1 Like