Just trying to get to grips with scripting in Unity, I’m trying to set up a basic 3rd person platform game. I’ve already completed the Lerpz tutorial, which was helpful in explaining the basics of unity however, I found that it was lacking in explanation with regards to setting up scripts to handle movement of characters etc
My problem is getting my character to turn with the camera following.
The following is applied to my base geometry character (no animations). I have then made a camera a child object of the character.
I appreciate that this is probably a really simple bit of code but this side of things is completely new to me and I’d be really grateful for the help.
Code:
var speed = 6.0;
var jumpSpeed = 8.0;
var gravity = 20.0;
private var moveDirection = Vector3.zero;
private var grounded : boolean = false;
function FixedUpdate() {
if (grounded)
{
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}
transform.eulerAngles.y += Input.GetAxis("Horizontal");
moveDirection = Vector3(0,0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection.y -= gravity * Time.deltaTime;
var controller : CharacterController = GetComponent(CharacterController);
var flags = controller.Move(moveDirection * Time.deltaTime);
grounded = (flags CollisionFlags.CollidedBelow) != 0;
}
@script RequireComponent(CharacterController)
EDIT: posted the wrong script originally :whoops: I’ve added the rotate bit in however, this has dramatically slowed my character down. . . obviously I can amend the figures from within the inspector to adjust this but I was wondering whether I have placed the rotation script in the wrong place and maybe it’s interfered somehow? Any pointers would be great- even if I’m doing it all wrong!
Thanks