3rd person moving with camera problem

I was trying to follow the 3rd person tutorial Third Person Controller | PlayCanvas Developer Site, my implementation is not perfect, but somehow it works, what I need is that camera orbit around player only on horizontal axis (I guess that would be x and z axis).

There is 1st person tutorial First Person Movement | PlayCanvas Developer Site but I don’t know how to offset camera and orbit around player also, so I couldn’t reuse this code

This rotation should affect forward direction, to put it simple, W should applyForce forward, and forward direction is where camera looks.

Also the tutorial use teleport and I don’t know how to change it to use applyForce, as I need collision unbroken.

Here is the link to the project
https://playcanvas.com/editor/scene/2131600

Id say your best bet is to not use their script, make a new entity that is a child of the player that is in the middle of the player, keep the camera where it is at but make it a child of the new entity, and use a simple code like this:

this.newentity = this.app.root.findByName('whatever you call it');
this.cam = this.entity;
this.movespeed = 1;
this.player = this.app.root.findByName('player name');

this.newentity.rotateLocal(0,this.movespeed,0);
this.cam.lookAt(this.player.getPosition())

This might need a little fine-tuning, but let me know if you need any help!

Thank you, but I don’t think this will give me behavior as I expect, as I need mouse to rotate camera, and make forward direction according to camera rotation, but I will try anyway

Ah. I don’t have enough experience to help here then, sorry.

Actually, if you describe how you want it to work or there is a game I can use for reference I might be able to figure it out.

In my example it is almost done, actually just to use applyForce instead of teleport would do the job

1 Like

To use applyForce, you can get the camera’s forward direction and apply the force like this: this.entity.rigidbody.applyForce(direction.scale(forceAmount)). For the camera rotation, you can make it follow the mouse but only move on the X and Z axes.