- Home /
Question by
DubstepDragon · Feb 22, 2014 at 03:26 PM ·
movementrpgsimplestrafe
Adding simple strafing to my character controller script...
I wonder how this can be achieved in the simplest of matters... as I already said, I want to keep this project simple and organized, limiting everything down and keeping my code clean and organized. This is my modified SimpleMove script from Unity Script Reference:
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(CharacterController))]
public class Move : MonoBehaviour {
public float speed = 3.0F;
public float rotateSpeed = 3.0F;
void Update() {
CharacterController controller = GetComponent<CharacterController>();
transform.Rotate(0, Input.GetAxis("Mouse X") * rotateSpeed, 0);
Vector3 forward = transform.TransformDirection(Vector3.forward);
float curSpeed = speed * Input.GetAxis("Vertical");
controller.SimpleMove(forward * curSpeed);
}
}
You might've noticed that I am using the mouse to rotate the player... and that is precisely what I want. I do not want an FPS style camera rotation, rather just rotation of the player itself on the horizontal axis.
Thank you all so much in advance! :D
Comment