Hey guys, I am trying to make a wind effect for my golf game, I get an “angle” value from 0 to 360 from the server, and I want to apply a force to the ball in the direction of the angle:
Tried this:
Let’s say the angle is passed as 90:
let force = 4;
this.windFactorInX = Math.cos(angle * Math.PI / 180) * force;
this.windFactorInZ = Math.sin(angle * Math.PI / 180) * force;
// this.windFactorInX will be calculated 0 here
// this.windFactorInZ will be calculated 4 here
this.ball.rigidbody.applyForce(this.windFactorInX, 0, this.windFactorInZ);`
but this seems to be flawed, it “only” works at a certain angle, the camera is facing eg:
At this angle from the camera, this will work, as the blue component is the Z component and also is 90 degrees, so the ball will go left correctly:
But if the camera angle changes to this, the same 90 degrees given will give the same X and Z values but now the X and Z components in the world space are exchanged so the ball goes towards the camera, because the Z: 4 force is being applied.