Move with mouse

Hi!
Is there any tutorial or any kind of help on how to move player with mouse clicks?
Thank you

Note: I’m assuming you want the user to click on the screen somewhere and have a character or object move to that click location.

I don’t think there is a tutorial per se, but some games on PlayCanvas do this. For example:

Going Around

There’s a couple of ways to do this:

The Simple Case: Solving for a Plane
Let’s assume your game world is a flat plane. In that case, you can calculate a ray that goes from the camera’s position (viewpoint) through the click coordinate on the screen (which you can get from the pc.CameraComponent#screenToWorld function). You then calculate the coordinate where that ray intersects that plane and you’re done.

The Harder General Case: Solving for an Arbitrary Game World
In this case, you probably want to use the PlayCanvas physics engine to do a raycast. You calculate the ray the same way, but this time, you use the raycastFirst function to determine the 3D point where the user has clicked. The ray is tested against all the collision components in your scene.

This project shows how to calculate a ray and use the raycastFirst function:

https://playcanvas.com/project/5141/overview/howto-entity-picking

2 Likes

I have seen the Going Around project and trying to understand it but still confuses me. New to all these and still have a lot to learn. I ll try again with the help of the other one.

Thank you very much for the quick response!