I need help with this! if anyone can

I have a scene with two objects (browser) and (player_1).
the navigator can scroll through all the scenes and control it with the keys A, S, D, W.

What I want is for player_1 to look in the direction the browser is in!

so I did it

var angle = Math.atan2 (browser.position.z - player_1.position.z, browser.position.x - player_1.position.x);
angle = angle * (180 / Math.PI);

player_1.rotation = new BABYLON.Vector3 (0, angle, 0);

<<<

player_1 spins but the front of the character never faces the position - I think it can be quaternion.
I tried running the player_1 in a simple way too and to my surprise, it spins wrong. (For example

player_1.rotation = new BABYLON.Vector3 (0, 90, 0);

when I press a button, it turns but it does not make 90 degrees before doing more than that.

The idea is that every time I select a location with the browser, player_1 goes back to that location.
Hi, I’ll try this and nothing.
player_1.rotationQuaternion = new BABYLON.Quaternion.RotationAxis (BABYLON.Axis.Y, angle);

I hope, thank you! xD

I am not sure if i fully understand your problem but assuming player_1 is a mesh, did you try the lookAt function?

player_1.lookAt(browser.position)

1 Like

Dude, I’ve been trying this code since yesterday and I already knew there was the (lookAt), but I could not remember - kkkkkkkk. :sweat_smile::rofl::rofl::joy::joy::blush:

Thanks you helped a lot with this function above, but it always gets a bit wrong.

I saved the day.

Still a bit wrong? Maybe it’s because you only wanted to rotate it around the Y axis in your example?
In that case you could try something like

player_1.lookAt(new BABYLON.Vector3(browser.position.x, player_1.position.y, browser.position.z))

to lock it to the height of the player_1 object. :slight_smile:

1 Like

It’s settled - what was wrong was my code.
Many thanks, @GreyWorks is working perfectly.

1 Like