hi,
i try to move my character with point and click control, but i want my player collide with any obstacle like box or someting. check the sample scene https://playcanvas.com/editor/scene/1234214
but, my character through the wall.
i’ve try with this.playerEntity.rigidbody.teleport(newPosition); like in my sample scene. but its make the charater move laggy, not smooth.
if (this.direction.lengthSq() > 0) {
// Move in the direction at a set speed
var d = this.playerSpeed * dt;
var newPosition = PointAndClick.newPosition;
newPosition.copy(this.direction).scale(d);
newPosition.add(this.playerEntity.getPosition());
// Position
this.playerEntity.setPosition(newPosition);
// Rigid body
//this.playerEntity.rigidbody.teleport(newPosition);
this.distanceToTravel -= d;
// If we have reached our destination, clamp the position
// and reset the direction
if (this.distanceToTravel <= 0) {
this.playerEntity.setPosition(this.targetPosition);
this.direction.set(0, 0, 0);
}
}
Hi @Gagan_Sukmawan, teleport is usually the way to do it when you want to use dynamic. Can you please show us what you mean by “laggy” movement? setPosition will not work in your usecase since you are trying to use dynamic rigidbodies.
I’ve just had a look at your project. I didn’t find the movement laggy as such, but if you mean that the user needs to keep holding down the mouse button to make the position move rather than click to go to a certain point like before, pathfinding might be the best way to fix this problem, especially since you want your character to be able to navigate around rigid bodies. For this, you can check out either PathFinding3D.js, @Leonidas’s extension, or this thread.
Hi @Gagan_Sukmawan and welcome! I’ve had a similar problem and it was caused because I set the camera position along with the player position. The solution may be to set the camera position in a postUpdate function or to make the camera entity as a child of the player entity and not use the script for this anymore.