So what I’m trying to accomplish is a basic character controller where you use A/D or left/right to rotate, and W/S or up/down to move forward and backward. So far, all I have is the rotation script.
var rotSpeed = 6;//setting the speed the character will rotate
var moveSpeed = 6;//setting the speed the character will walk
function Update()
{
var v3 = Vector3 (Input.GetAxis ("Horizontal"), 0.0);
transform.Rotate (v3 * rotSpeed * Time.deltaTime);
}
How should I go about making the character move forward/backward based on their current rotation?
You could use Translate:
var rotSpeed = 6;//setting the speed the character will rotate
var moveSpeed = 6;//setting the speed the character will walk
function Update()
{
var v3 = Vector3 (Input.GetAxis ("Horizontal"), 0.0);
transform.Rotate (v3 * rotSpeed * Time.deltaTime);
v3 = Vector3 (0.0, 0.0, Input.GetAxis("Vertical"));
transform.Translate (v3 * moveSpeed * Time.deltaTime);
}
But the vector v3 seems wrong - in order to rotate about Y, it should be:
var v3 = Vector3 (0.0, Input.GetAxis ("Horizontal"), 0.0);
NOTE: Moving a simple collider with Translate makes it pass through other colliders. If you want the object to be constrained by other colliders, it should have at least a Rigidbody attached. The behaviour would be somewhat weird, however: the object would shake a lot when trying to pass through a collider, and could even succeed if the collider was thin enough. The CharacterController would be the best alternative - attach a CharacterController to your character and try the example script of SimpleMove (SimpleMove applies gravity automatically).