- Home /
Question by
XxFlyingCarrotxX · May 28, 2019 at 08:49 PM ·
3rd person controller3rd person camera
How do I make a Third Person mouse Movement?
I have made a project. I am have put walking animations using Blend Tree, a 3rd person mouse look system. However, I can't seem to put an essential part of a 3rd person game. I want to be ale to freely look any direction with my mouse ( I can do that already) when i am not moving, but when the character is going forward, I want the character to move toward the direction of mouse look. So, the character should correspond and rotate to the direction the camera is facing and move in that direction. I made the mouse look,here is my script:
public float mouseSensitivity = 10.0f;
public Transform target;
public float dstFromTarget = 2.0f;
public float yaw;
public float pitch;
public Vector2 pitchMinMax = new Vector2(-50, 85);
public float rotationSmoothTime = 0.02f;
Vector3 rotationSmoothVelocity;
Vector3 currentRotation;
void LateUpdate()
{
//Mouse Movement
yaw += Input.GetAxis("Mouse X") * mouseSensitivity;
pitch -= Input.GetAxis("Mouse Y") * mouseSensitivity;
// Claemp
pitch = Mathf.Clamp(pitch, pitchMinMax.x, pitchMinMax.y);
// Positioning
transform.eulerAngles = currentRotation;
transform.position = target.position - transform.forward * dstFromTarget;
// Smoothening
currentRotation = Vector3.SmoothDamp(currentRotation, new Vector3(pitch, yaw), ref rotationSmoothVelocity, rotationSmoothTime);
}
}
and this is my movement Script:
private Animator anim;
public float speed = 3.5f;
public float animspeed = 2.0f;
// Start is called before the first frame update
void Start()
{
anim = GetComponent<Animator>();
}
void Update()
{
anim.speed = animspeed;
// Move
// Right, Left
float Axis = Input.GetAxis("Horizontal") * speed;
// Front, Back
float translation = Input.GetAxis("Vertical") * speed;
translation *= Time.deltaTime;
Axis *= Time.deltaTime;
transform.Translate(Axis, 0, 0);
transform.Translate(0, 0, translation);
// blend tree shit i dont undertsand
var x = Input.GetAxis("Horizontal") * speed;
var y = Input.GetAxis("Vertical") * speed;
Move(x, y);
}
private void Move(float x,float y)
{
anim.SetFloat("VelX", x ) ;
anim.SetFloat("VelY", y ) ;
}
}
Pls help.
Comment
Your answer