4 Directional Looking / Cross positional aiming + Leg alignment?
I'm trying to setup 4 directional looking for my player. Where basically the player can look up, down, left, and right. But if they look past a certain degree either left, or right. The legs and torso realign to the new angle. Similar to how Source games handle their cross positional aiming.
I'm wondering what the best way to do this in Unity would be. Right now I have my mecanim setup with a blend tree, and I have two mecanim Floats "LookAngleX" and "LookAngleY" and that works great.
http://webm.host/eb8df/vid.webm
As the video shows above, it looks just fine when I have the two Floats setup to the camera's X and Y rotations.
lookAngleX = camera.localRotation.y;
lookAngleY = camera.localRotation.x;
But I have nothing setup to handle if the Y rotation goes over "for example" a 45 degree angle, to realign the legs and look forward again.
If anyone has done this before, please share how you did it. It would help a lot!
So I've been going at this stuff all day, "I'm dying oh god help me"
What I've come to find out is, I have a mecanim blend tree that relies on two floats. - "lookAngleX" and "lookAngleY" for Up, Down, Left, and Right ai$$anonymous$$g/looking.
I have these two floats hooked up to my camera's rotation.
[code] [NetSync]
public float moveX, moveY, velocity, lookAngleX, lookAngleY;
public Vector2 lookPos;
protected override void Update()
{
base.Update();
if (IsOwner)
{
//Animator
moveX = Input.GetAxis("Horizontal");
moveY = Input.GetAxis("Vertical");
velocity = controller.velocity.magnitude;
lookAngleX = lookPos.y;
lookAngleY = lookPos.x;
//Looking
lookPos = new Vector2(camera.rotation.x, camera.rotation.y);
if (lookAngleX >= 0.4f || lookAngleX <= -0.4f)
{
print("Angle past 0.4f/-0.4f");
//model.transform.rotation = Quaternion.Euler(0, camera.eulerAngles.y, 0);
}
}
//Animator
animator.SetFloat("$$anonymous$$oveX", moveX);
animator.SetFloat("$$anonymous$$oveY", moveY);
animator.SetFloat("Velocity", velocity);
animator.SetFloat("LookAngleX", lookAngleX);
animator.SetFloat("LookAngleY", lookAngleY);
}[/code]
So if the camera moves / the player looks around, then so does the floats for mecanim. And it works perfectly when the player is looking forward.
The problem is, when the player's camera rotates, such as 90 degrees. The floats are drastically changed, and possibly inverted. Which completely wrecks my mecanim blend tree, since it depends on a float between -0.4f and 0.4f, or something like that. But since the camera rotated, the float ends up completely different.
I can't quite think straight, but it seems like I need to change how my floats are set with the camera, it seems like it needs to account for the model rotation as well?
I'm terrible at explaining this..
Your answer
Follow this Question
Related Questions
Rotate LOCAL y axis to match Joystick input 0 Answers
Rotating player to look in a fixed direction but on a planet (sphere world) 0 Answers
How to align fps Player to surface normal and use look At on a target 0 Answers
FromToRotation for a die / dice 0 Answers
i am using a code to make my cube walk with character controller ,but when i play the cube spins. 0 Answers