[SOLVED] Rotate player to mouse position

I am making a small 3d game, where you have to shoot zombies coming at you. The camera is at a fixed angle from the top, a bit like that project. I’ve tried using some code snippets from that project, but it doesn’t as properly as I expected.

What I want is that the player should only rotate to the direction of the mouse. The direction of the controls should stay the same, regardless of the direction.

Here is my link to the project

Thanks in advance

Hi @SayHiToMePls! Maybe you can use the project below. I think you can use the CameraOrbit script on your camera entity and add your player entity to the Focus Entity attribute of it. Make sure the camera entity is no child of your player entity anymore.


I tried it myself and it didn’t work as I expected at first. Render component is not supported, so you need to use the old model component. You also need all the scripts that are attached to the camera entity. Apart from that I disabled some camera control code from your own project. Below the setup with your project.


And after all I realize you mean something else. :man_facepalming:

Below is another example project. I hope this will help you.


It is, but you need to grab newer script from the engine folder.

Or the one from the tutorials. That has been updated for the render component too :slight_smile:


Thanks. I don’t know exactly where our custom project (based on the tutorial) is modified. So at this moment the custom project doesn’t support the render component. I will see if I can update the project soon.

The majority of it (if not all) would be in _buildAabb in the orbit camera script

1 Like

Thanks, but how do I set the controls, so the player always goes in the same absolute direction?

E.g.: When I press the W key, the player goes along the positive x axis, even when I rotate it to a different direction. I.e., I don’t want to use var forward = this.entity.forward;

I think in the last example project that’s already working as far I can see in the script?

Wait, I just got it to work…somehow.

I just made the camera not being a child of the player.

Now my only problem is that the player only rotates whenever it stands completely still.

Which example project do you use?

And after all I realize you mean something else. :man_facepalming:
Below is another example project. I hope this will help you.
PlayCanvas 3D HTML5 Game Engine

Could you please take a look at my project?

Somehow, my camera rolls backwards and when I move my mouse, it gives an error with .screenToWorld()

here to my project

You didn’t apply the correct entities to the attributes of the stript on your player entity.

Can you please show me exactly what I’ve done wrong? I can’t see the difference when comparing my code and the example code.

OK, I admit, that is pretty embarassing.

Thank you so much though! :smiley:

There is just one problem left:

My player weirdly rotates when it gets the center (0, 0, 0).

What is the problem there?

No idea. I’m on mobile at the moment, so unable to check your project in detail. Is the same problem in the example project?