CylinderGeometry lookAt and its rotation

Hi all!

I have a player figure using a CylinderGeometry and holding a spear. I want it to look at my mouse. The cylinder initially is “standing up” but lies flat as soon as I use the “lookAt”.

I have a fiddle with reduced code here: Edit fiddle - JSFiddle - Code Playground (the player figure starts to look at the mouse after 1 second). I tried a lot of combinations of setRotation and setting the up property but can’t make it work.

Any ideas appreciated!

This example from the collection might help.

RotationToTargetObject

Thank you, but this gets the same result as the player.lookAt for me. I now implemented the same logic as from that example with rotationMatrix.lookAt(...) and player.quaternion.setFromRotationMatrix(rotationMatrix) but it gets the same result as before, that the cylinder will lie flat on the ground and the initial cylinder rotation is not kept.

I’ve simplified your fiddle so it’s easier to see what’s going on. I suggest you start from the following code and change it according to your needs step by step: Edit fiddle - JSFiddle - Code Playground

Uiiii, wow thank you so much!!

I think I messed up my coordinate system as I have x and y for width and depth and use the z axis for height (from ground to sky). The GridHelper is vertical to my floor in my app. I will try to switch to using y for the height axis, I guess that might be the culprit source.

Okay, I got it now. I changed everything to being y the up-axis and removed setting the player figure’s up attribute. Big thanks!