Trying to set up a script where the camera follows the player and is always looking ahead, at first I thought the camera wasn’t moving, then I realized it was the player that wasn’t rotation, how exactly could I make the player rotate while using the standard movement script from the reference?
/// This script moves the character controller forward
/// and sideways based on the arrow keys.
/// It also jumps when pressing space.
/// Make sure to attach a character controller to the same game object.
/// It is recommended that you make only one call to Move or SimpleMove per frame.
var speed : float = 6.0;
var jumpSpeed : float = 8.0;
var gravity : float = 20.0;
private var moveDirection : Vector3 = Vector3.zero;
function Update() {
var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded) {
// We are grounded, so recalculate
// move direction directly from axes
moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,
Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
controller.Move(moveDirection * Time.deltaTime);
}
Because, From what I understand (Which I don’t understand the Horrizonal and Vertical Movement thing, it’s just moving it left/right forward/backwards, not moving it Forward and changing the angles, which is what I want to do. Honestly. I would rather my character always be moving forward and the way he is facing change.
Are you trying to do it for learning? Because you could use the Character Controller Assets which has all you need including a first or third person controller. What you are missing is the mouse script which control the orientation of the camera and the direction of the player.
– fafasetry this. it works great for me: function Update() { var speed : float = 5 transform.eulerAngles.y += (Input.GetAxis("Horizontal") * speed); }
– TRiToNDREyJAsince your learning, ill explain it. eulerAngles is rotation relative to its origin i think. speed is the amount of degrees at a time. when you press left or right, value is set to 1 or -1. it is then multiplied by your speed then added to your eulerAngle rotation. hop this helped :)
– TRiToNDREyJA