# How to make the characters always facing the front, no matter how the camera rotates?

**URL:** <https://forum.babylonjs.com/t/how-to-make-the-characters-always-facing-the-front-no-matter-how-the-camera-rotates/43718>\
**Category:** Questions\
**Tags:** character-controller\
**Created:** [August 31, 2023, 7:55am UTC](https://forum.babylonjs.com/t/how-to-make-the-characters-always-facing-the-front-no-matter-how-the-camera-rotates/43718 "2023-08-31T07:55:02Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![pxim](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pxim/32/26372_2.png) [@pxim](https://forum.babylonjs.com/u/pxim)\
**Post date:** [August 31, 2023, 7:55am UTC](https://forum.babylonjs.com/t/how-to-make-the-characters-always-facing-the-front-no-matter-how-the-camera-rotates/43718/1 "2023-08-31T07:55:02Z")

</div>

DEMO: [Physics V3 Simple scene with Aggregate | Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#Z8HTUN#179)

No matter how the camera rotates, when holds W, the character walks forward, the orientation is always forward

This is the effect I want.  
Uploading: 1693468035062.mp4…  
video：[https://pan.baidu.com/s/1hnLni-wMWApcEE0FXLG0Zw?pwd=9j7t](https://pan.baidu.com/s/1hnLni-wMWApcEE0FXLG0Zw?pwd=9j7t)  
[metaverse-third-three](https://res.91yunlifang.com/caselib/bafc3b16-12dc-4f1d-bf20-ea04a3c736bd-resfile/index.html)

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [August 31, 2023, 11:18am UTC](https://forum.babylonjs.com/t/how-to-make-the-characters-always-facing-the-front-no-matter-how-the-camera-rotates/43718/2 "2023-08-31T11:18:50Z")

</div>

Hello!

Instead of using the camera target, parent the camera to your character root and position it accordingly: [Physics V3 Simple scene with Aggregate | Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#Z8HTUN#679)

I detached the camera controls, since what we want of the mouse movement is to rotate the character, not the camera, you just have to add that part 🙂

---

<div class="post-metadata">

**Author:** ![pxim](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pxim/32/26372_2.png) [@pxim](https://forum.babylonjs.com/u/pxim)\
**Post date:** [September 1, 2023, 12:45am UTC](https://forum.babylonjs.com/t/how-to-make-the-characters-always-facing-the-front-no-matter-how-the-camera-rotates/43718/3 "2023-09-01T00:45:28Z")

</div>

In this case, the camera’s rotation zoom and so on is gone.  
I want to keep these functions

---

<div class="post-metadata">

**Author:** ![pxim](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pxim/32/26372_2.png) [@pxim](https://forum.babylonjs.com/u/pxim)\
**Post date:** [September 1, 2023, 7:54am UTC](https://forum.babylonjs.com/t/how-to-make-the-characters-always-facing-the-front-no-matter-how-the-camera-rotates/43718/4 "2023-09-01T07:54:21Z")

</div>

![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/9/9/99e31e3eb418ea9f908dd8d4ed914cc510a7edcb.png)  
I added this code, and the characters can always face the front.

But why is-1.6, I don’t understand, this value is experimented by me, is there any more correct way of writing?

And after adding this code, when holding w, i can’t move forward

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [September 1, 2023, 11:19am UTC](https://forum.babylonjs.com/t/how-to-make-the-characters-always-facing-the-front-no-matter-how-the-camera-rotates/43718/5 "2023-09-01T11:19:44Z")

</div>

You can implement the zoom manually

---

<div class="post-metadata">

**Author:** ![pxim](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pxim/32/26372_2.png) [@pxim](https://forum.babylonjs.com/u/pxim)\
**Post date:** [October 7, 2023, 5:33am UTC](https://forum.babylonjs.com/t/how-to-make-the-characters-always-facing-the-front-no-matter-how-the-camera-rotates/43718/6 "2023-10-07T05:33:36Z")

</div>

I still feel that the perspective of rotating characters is better,  
It’s just that in this case, after pressing W, the angle is changed, but the character does not move.

[Physics V5 Simple scene with Aggregate | Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#Z8HTUN#685)

---

<div class="post-metadata">

**Author:** ![pxim](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pxim/32/26372_2.png) [@pxim](https://forum.babylonjs.com/u/pxim)\
**Post date:** [October 7, 2023, 8:02am UTC](https://forum.babylonjs.com/t/how-to-make-the-characters-always-facing-the-front-no-matter-how-the-camera-rotates/43718/7 "2023-10-07T08:02:26Z")

</div>

```auto
player.body.setLinearVelocity(frontVector, player.transformNode.getAbsolutePosition());

hk.setTargetTransform(player.body, player.transformNode.getAbsolutePosition(), quaternion);

```

These two sentences are executed at the same time,  
the characters will not move,  
I don’t know how to solve

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [October 9, 2023, 11:01am UTC](https://forum.babylonjs.com/t/how-to-make-the-characters-always-facing-the-front-no-matter-how-the-camera-rotates/43718/8 "2023-10-09T11:01:12Z")

</div>

```javascript
hk.setTargetTransform(player.body, player.transformNode.getAbsolutePosition(), quaternion);

```

This line is not going to do anything, because you need to pass the position where you _want the player to be_, not the position they already have. See the function documentation:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/1/9/195602358ce23bcb058f9e419e3483887a1f35a6.png)

And since setTargetTransform already sets the velocity of the body, you don’t need to call setLinearVelocity.

Here’s an example where I’m setting targetTransform to a desired position: [Physics V5 Simple scene with Aggregate | Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#Z8HTUN#718)

---

<div class="post-metadata">

**Author:** ![pxim](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pxim/32/26372_2.png) [@pxim](https://forum.babylonjs.com/u/pxim)\
**Post date:** [October 12, 2023, 5:14am UTC](https://forum.babylonjs.com/t/how-to-make-the-characters-always-facing-the-front-no-matter-how-the-camera-rotates/43718/9 "2023-10-12T05:14:44Z")

</div>

alright, thank you very much
