Moving player relative to arcRotateCamera's direction

I’ve been trying to move a sphere relative to the arcRotateCamera’s direction and I just can’t get it to go in the right direction. I’m sure that I’m messing up the angles somehow and I would really appreciate it if somebody could point out what exactly it is that I’m doing wrong.

Here’s the playground:
https://playground.babylonjs.com/#IC2IHY#4

Hi @ignite, were you looking for something like this?

https://playground.babylonjs.com/#IC2IHY#9

1 Like

@gbz, yes! this is exactly what I was looking for. Could you please explain how you calculated the rotation axis though? That is the only part that has me a bit confused

Added the line

const rotationAxisY = BABYLON.Matrix.RotationAxis(BABYLON.Axis.Y, -camera.alpha + Math.PI / 2 + angle - Math.PI);

Could be simplified by merging the Math.PI’s :slight_smile:

Calculated it through trial and error. Knew this angle had to depend on 2 variables:

  • ArcRotateCamera’s alpha
  • Angle based on whether W, A, S, or D is pressed

so added both to line of code above. Through trial and error, saw that there was a “negative” dependence on the ArcRotateCamera’s alpha. Then I just added a couple factors of Math.PI through guessing until it worked :smiley:

1 Like

@gbz, thank you. I had been trying to use a freeCamera-style approach from a playground I saw. Should have just used the alpha.

2 Likes