How to applyForce to my player(Ball) in the direction my camera is facing?

Hi, I have got a basic controller working for rolling a ball.
I now wanted to control the ball to move in the direction the camera is facing

Here is the working code so far I got,

I got the direction the camera is facing with the help of the below line of code.
But I dont know how to apply it to the Direction vector before using it to move the player.

camera.direction = camera.getFrontPosition(1).subtract(camera.position).normalize();

I tried multiplying it with the direction vector, adding it with the direction vector also multiplying by a scalar value. Nothing seems to work. Maybe I am just weak in maths :frowning:

Hi, it works if you remove the camera. bit, and calculate the direction before each impulse:

@Gijs Ah I forgot to mention I did get the direction calculation for the camera inside the scene.registerBeforeRender() callback. But the problem I was facing was how to combine the calculated camera direction and the keyboard input direction to create a new direction which will be applied on the ball.

Oh I see, this may be it:


@Gijs Ah perfect thank you very much.

1 Like