- Home /
Mecanim Camera modifications
Greetings,
I have my character setup completely like Mecanim, and it is working fine without any problems. However, If some of you have noticed, the mecanim camera stays stuck to the character movement, and we can't move it around with our mouse or do pretty much anything with the camera. Does anyone have any ideas of how I could change the script of the default mecanim camera, to allow movement with the mouse(like world of warcraft camera movement), and work with mecanim animations and controls at the same time?
With features like: - zooming in and out - moving the character with the camera (Holding RMB and moving the character at the same time) - Moving only the camera (holding the LMB)
I am using the BotControlScript for mecanim btw.
Here is the mecanim camera script (C#):
using UnityEngine;
using System.Collections;
public class ThirdPersonCamera : MonoBehaviour
{
public float smooth = 3f; // a public variable to adjust smoothing of camera motion
Transform standardPos; // the usual position for the camera, specified by a transform in the game
Transform lookAtPos; // the position to move the camera to when using head look
void Start()
{
// initialising references
standardPos = GameObject.Find ("CamPos").transform;
if(GameObject.Find ("LookAtPos"))
lookAtPos = GameObject.Find ("LookAtPos").transform;
}
void FixedUpdate ()
{
// if we hold Alt
if(Input.GetButton("Fire2") && lookAtPos)
{
// lerp the camera position to the look at position, and lerp its forward direction to match
transform.position = Vector3.Lerp(transform.position, lookAtPos.position, Time.deltaTime * smooth);
transform.forward = Vector3.Lerp(transform.forward, lookAtPos.forward, Time.deltaTime * smooth);
}
else
{
// return the camera to standard position and direction
transform.position = Vector3.Lerp(transform.position, standardPos.position, Time.deltaTime * smooth);
transform.forward = Vector3.Lerp(transform.forward, standardPos.forward, Time.deltaTime * smooth);
}
}
}
Because I have tried to put some camera scripts before, however they didn't work well at all with the mecanim animations and controllers. Tell me if I should the other mecanim controllers and animation scripts as well.
Thanks in advance.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Gun lag behind camera 1 Answer
What are the errors here? 1 Answer
View through objects 2 Answers
How would I script camera sensitivity? 0 Answers