Tomasz Drozdowski
Tomasz Drozdowski

Reputation: 43

Three.js / Rotate object around its' Y-axis to look in particular direction

I tried to wrap my head around it for at least a week, but it's too heavy for me. The problem is that when I click on particular coordinates on the PLANE, i want my 3d model to rotate to face the new coordinates, and then change it's position to match the new coordinates ( it would be nice if you also explain to me how to declare objects' speed and move it with that speed ).

I know it has to do something with THREE.Matrix4() function.

(If You ever played starcraft or similar game, you'll know what I'm up to ;> )

Here is what I have so far:

http://f.cl.ly/items/1u2q463D1Y0K3G1W2g3P/bf.jpg

And here is what I want to achieve:

https://i.sstatic.net/Q2vrs.jpg

Upvotes: 0

Views: 1339

Answers (1)

Stemkoski
Stemkoski

Reputation: 9045

First, you will need to do raycasting, to calculate the position of the plane that your mouse cursor intersected when you clicked, check out http://stemkoski.github.io/Three.js/Mouse-Over.html for a related example with code. Then, once you know the position, you can use the lookAt function: see http://mrdoob.github.io/three.js/examples/misc_lookat.html for details.

Upvotes: 1

Related Questions