@lordofduct A little bit about me, something I should have mentioned but is probably pretty obvious now. I don’t have much education in the way of calculus, other than what little I’ve read in books and picked up.
Regarding the confusion I caused, I’ve created an illustration of what this input point, the origin, and the opposite quadrant I am talking about are:
If those roman numerals are wrong, I apologize, I never got that down in school and I don’t see much use for learning it today, though it should be pretty easy. Just thought I would put it in proper notation.
This illustration is important. Its the screen in my game. The “input point” is the mouse pointer, and I want to create a Vector (ignore the dimension for a second) exactly opposite it on this graph. I’m trying to use the angle from the mouse position to the origin (screen center). That angle should be opposite the mouse pointer, so I had a simple multiplication for the chainDirection Vector2 (the mouse position relative to the origin) by negative one, assuming that would flip the signs of the coordinate values to create an oppositely pointing angle. I didn’t do too much hard thinking on that part… and neglected to leave that out of the code I posted.
I understand the concept of acute angles, and I know the Vector2.Angle function always returns an acute angle. I had code in place to account for that, but I removed it because I was confused.
Why I am doing all of this: to create the effect of fluidity in flight when playing this game, I have a few game objects which control the camera position and orientation. When one of these moves or changes orientation, a few functions are called to Lerp the camera’s local position to those gameobjects. So when I turn towards the right by moving the mouse to the right (the craft follows the mouse’s direction continuously), the ship should lag behind the camera as the whole thing turns right.
So when I’m turning right, the ship is moving LEFT relative to the camera and the users viewscreen.
Does that make sense?
If you’re this far, on with the explanation: the angle will be given to the Cos and Sin functions to get the ratio, which would be multiplied by the radius I supply, to find a new position for the LerpTarget at the opposite angle of the mouse pointer (as in the opposite screen quadrant). These two values will take up the x and y values of the Vector3 MovementLerp, and a third value for the Z component value in this Vector3.
All of it should create a smooth visual effect of the camera kind of looking ahead as it turns, and the ship gradually catching up.
Man if you have trouble with this, I don’t think you or anyone else would understand my previous code… it was very arcane and difficult to understand OR explain.
The code with changes to accomodate the acute angle returned by the Vector2.Angle foo, and the sign flip from a negative one multiplication on the chainDir:
Vector2 chainDirection = new Vector2 (relativeMInput.x, relativeMInput.y)* -1; //Get opposite direction by flipping value signs
float rad = Vector2.Angle (new Vector2 (relativeMInput.x, 0f), chainDirection) * Mathf.Deg2Rad; //Compute angle and convert to Radians because C# AND MANY OTHER language's math library foo's take radian arguments!
float dirCos, dirSin = 0f;
if (relativeMInput.y < 0f) { //If the mouse is below the X axis...
rad *= -1; //Make the sign of the angle negative so we can get the right angle
}
print ("RADIANS between center screen and mouse pointer is: " + rad+ " direction is:" + chainDirection );
//Assuming these angle calculations are right...
dirCos = Mathf.Cos (rad);
dirSin = Mathf.Sin (rad);
print ("DirCos = " + dirCos + "Sin = " + dirSin);
movementLerp = new Vector3 (cameraOffset * dirSin, cameraOffset * dirCos, ZCamOffset);
print ("MovementLerp = " + movementLerp);