Position ahead in an arc

I have a question.
I have a camera and a direction.

I get the direction the player is facing and find a random position in the distance and I want to draw something there. But I don’t want it to be in front of the player all the time.

I want to get a new position instead of straight ahead, in an arc of 45 degrees from center of straight ahead at that random position.

This is a mess but hope it helps.
Step one get player position and direction.
Calculate a new position distance from player.

I want to take that new distance from player and get a vector3 based on a 45 degree arc -22 to 22.

This is a grid base game so the direction is verify simple, but I know you guys know how to do this in a generic form where it doesn’t matter.

image

Thanks…

1 Like

From my understanding, you are trying to get a point between a reference point and another target and then rotate that point around the reference point in a 45 degree range and then retrieve the current position ?

Yes. I want to create a random function for rotating with in 45 degrees of the point 24 degrees to each direction.

I assume sin/cos on the x,z will do it, but I’m not a match guy didn’t want to waste time trying that if that is not correct.

You can simply do the following :

  1. Interpolate between the reference node (node.A) and the target node (node.T).
  2. Create another new node (node.B), then set its location to the interpolation.
  3. Add the new node (node.B) to the reference node (node.A)
  4. Rotate the reference node (node.A), node.B will rotate with node.A around node.A center.
  5. Retrieve the current position of node.B in the field.

Or else use the polar coordinate system if you want some troubles :sweat_smile: in which you will convert an angle to a coordinate, i have made something similar before on 2d stuff but i don’t have the enough knowledge to reproduce that on 3d stuff.

1 Like

It will work, if you draw the right angle for the right vector component, as i recall, the angle is represented between the (Vx, Vy, Vz) spatial components with the norm (x, y, z) of the rootNode, you may want to eliminate y or z to keep it simple.

If you just want to pick a random point x distance away between +/- 24 degrees… then I’d just use Quaternion.fromAngles and then multiply that rotation by new Vector3f(0, 0, distance)

…add that to your current location and Bob’s your uncle.

1 Like