right now Im trying to script a character controller for my character, I would like to make a 3rd person controller. example like in the star wars quest for R2D2.
from my research at unity site...I found 2 type of script that Is one from Lerpz tutorial and another one from Character animation, But the problem Is, It doesn't teach me about the character controller from A to Z because it's already there to be used. I understand It a little bit.
can anyone point me to the right direction on how to do a basic character controller walk and jump and understand what im doing.
The author explains in a little more detail what the controller script is actually doing.
What I often do is take a look at the "pre-written" scripts in the tutorials from Unity and then cut and paste any lines of code I don't understand in to Goggle and cross my fingers that someone knows what the heck it does :)
okay..I'v try using the Penelope iPhone tutorial character controller and try to port the controller for Unity3d not the iPhone version and have a problem.
as for now my character can walk but cannot jump,if I press the jump button it will slide faster on the ground can someone help me..what did I do wrong
this is my code :
var speed = 0.0;
var jumpSpeed = 0.0;
var inAirMultiplier = 0.0;
var gravity = 20.0;
private var thisTransform : Transform;
private var character : CharacterController;
private var velocity : Vector3;
private var canJump = true;
function Start()
{
thisTransform = GetComponent(Transform);
character = GetComponent(CharacterController);
}
function FaceMovementDirection()
{
var horizontalVelocity : Vector3 = character.velocity;
horizontalVelocity.y = 0;
if(horizontalVelocity.magnitude > 0.1)
thisTransform.forward = horizontalVelocity.normalized;
}
function Update()
{
var movement = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
movement.y = 0;
movement.Normalize();
if ( character.isGrounded )
{
if (canJump && Input.GetButton("Jump"))
{
// Apply the current movement to launch velocity
velocity = character.velocity;
velocity.y = jumpSpeed;
canJump = true;
}
}
else
{
// Apply gravity to our velocity to diminish it over time
velocity.y += Physics.gravity.y * Time.deltaTime;
// Adjust additional movement while in-air
movement.x *= inAirMultiplier;
movement.z *= inAirMultiplier;
}
movement += velocity;
movement += Physics.gravity;
movement *= Time.deltaTime;
// Actually move the character
character.Move( movement );
if ( character.isGrounded )
// Remove any persistent velocity after landing
velocity = Vector3.zero;
// Face the character to match with where she is moving
FaceMovementDirection();
}
@script RequireComponent( CharacterController )