Question by
gh1337 · Dec 16, 2019 at 01:09 AM ·
camerarotationplayer movementthird-person
Rotate character body alongside movement.
I want to have a third person controller wherein the camera is at a fixed position and rotation away from the player at all times. The angle which the character faces should be entirely independent of the camera.
If a character spawns facing north, if I press "S" they should start moving south and the character should be facing south.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ThirdPersonCharacterController : MonoBehaviour
{
public float Speed;
void Update()
{
PlayerMovement();
}
void PlayerMovement()
{
float hor = Input.GetAxis("Horizontal");
float ver = Input.GetAxis("Vertical");
Vector3 playerMovement = new Vector3(hor, 0, ver).normalized * Speed * Time.deltaTime;
transform.Translate(playerMovement, Space.Self);
}
}
Comment