#setRotation to match player rotation

1 messages · Page 1 of 1 (latest)

tender charm
#

Hi guys,

I am trying to make an entity face the same way the player is, but I am unsure how to setup the vector2 for setRoatation.

I am currently using this:

entity.setRotation({x: (player.getViewDirection().x), y: 0});

But it isn't working.

Any help would be greatly appreciated 😉

warm light
#

exclude as in setting it to 0

tender charm
#

ahh, I forgot it's a vector 3. How would I do that, as I thought the ".x" after it would only take the x axis?

warm light
#

well you still have to define other axis

#

which axis do you need

tender charm
#

shows it only needs 2 axis?

warm light
#

ah right

#

it doesnt need z axis

tender charm
#

yeah, so setting y to 0 would leave as is right? then matching x to the player view x I expected to work

warm light
#

gimme a sec

tender charm
#

Thanks 🙂

warm light
#

i forgot setRotation is Vector2

#

ill brb

#

@tender charm since view direction returns the 'direction' the player is looking at (ex. looking at positive x returns 1 for x), you might need math for this

tender charm
#

ahh, okay, I will give that a go, thanks!

#

I can't work out the math for this, vectors twist my brain too much lol.

I will try and find another way, thanks though Seawhite!