[SOLVED] Player able to rotate and move at the same time


Currently I working on a project which player able to look at the mouse position (lookat.js) and clamp it along Y axis. It work well but the problem come when I add movement.js. The code of movement.js is from the realtime player tutorial movement.js and it use this.entity.forward or this.entity.right to move the player.

When I try to launch the game the movement.js and the lookat.js do not work as I expected. It either looking forward and move forward or the player stay in that position and look at the mouse position. Is that other ways to make the movement.js and lookat.js able to work simultaneously ?

This is the project link: https://playcanvas.com/editor/scene/1185032
if you launch it, you should get the idea what am I talking about.

Thanks for helping.


Hi @Elliot! I made an attempt, but unfortunately my knowledge is insufficient to find out why the result is not as expected. Other than that, I think the Third Person Controller does what you want, so maybe you could check that out.

1 Like

@Albertos Thanks for reply. I take a look at the link that you share, actually it quite good. But I wanna do something like a tank game and isometric camera angle.

Third Person Controller the direction define by the camera but what I trying to achieve is direction define by mouse position. The reason that I wanna done it in isometric due to it is easier to observe the surrounding and environment.

Alright. In my own game I use kind of the same way of movement, but the biggest difference is that I don’t use physics. So I can use translateLocal to move my player forward in the direction of the mouse. I hope someone else can see why your player is not moving in the right direction.

1 Like

Wow, it does fix my problem. translateLocal can move without bother the rotation of player but the drawback is the player will not fall off when out of the plane. Btw thanks for helping again.

That’s right. Nor will it stop for obstacles. I use sensors (raycasts) for this, but this requires a lot of extra work. It is best to solve the current problem. I expect it to be something small.

I forked the project, so if someone else wants to see what’s wrong they can look at the project below.


1 Like

Hello, the main issue is that when the key.ispressed the mouse pointer don’t move so the lookat function become useless, i don’t know if there is a way to solve that since i never had the need to dig into it, from what i noticed around it’s a pretty common issue in all games that use the keys to move and the mouse as in Winter Blast game. You should focus on a way to bypass this limitation. Good luck.

1 Like

Thanks for the advices.

So far what I get is to separate the head and body part. Add movement.js to the lower part (make the lower part transparent to make it invisible) and add lookat.js to the upper part. I get the idea from this project but unfortunately it not updated to the latest engine otherwise it will be a good start for those who wanna do an isometric 3D game. Hope the owner can updated it in the future. :pensive:

Hi @Elliot! I asked @yaustar to look into this problem and he made a sample project. I think it works wonderful! You can fork this project and tweak it where you need.

As far as I understand the solution to your problem is to make your model as a child of your rigidbody entity. Because you don’t rotate the rigidbody itself when you use lookAt, your rigidbody entity falls back to the original rotation when you apply some force.


Wow, that what I imagine for and it work so nice. Thanks @yaustar for made this project.