Hello I’m new to Unity. I’ve imported an animated character into my scene. The character has a walk and idle animation for a Third person shooter game I’m working on. I’ve added some code that allows the animations to play when in game mode. My problem is the character only walks in place when I hit the up button. I think I have to add a ThirdPersonController script but I am not sure. How do I make my character move when I hit the up button?
This is the script I have so far:
var speed : float = 1.0;
var rotateSpeed : float = 3.0;
function Start ()
{
// Set all animations to loop
animation.wrapMode = WrapMode.Loop;
var controller : CharacterController = GetComponent(CharacterController);
transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
if (controller.isGrounded)
{
// We are grounded, so recalculate
// move direction directly from axes
moveDirection = Vector3(0, 0,
In
This is class controller : : call this function in update()
void GetLocomotionInput()
{
var deadZone=0.1f;
TP_Motor.Instance.VerticalVelocity=TP_Motor.Instance.MoveVector.y;
TP_Motor.Instance.MoveVector=Vector3.zero;
//If movement in z-axis ie up key pressed
if(Input.GetAxis("Vertical")>deadZone || Input.GetAxis("Vertical")<-deadZone)
{
TP_Motor.Instance.MoveVector+=new Vector3(0,0,Input.GetAxis("Vertical"));
}
//If movement in x-axis ie down key pressed
if(Input.GetAxis("Horizontal")>deadZone || Input.GetAxis("Horizontal")<-deadZone)
{
Motor.Instance.MoveVector+=new Vector3(Input.GetAxis("Horizontal"),0,0);
}
}
this is class motor : :
void ProcessMotion()
{
//Transform MoveVector to world space
MoveVector=transform.TransformDirection(MoveVector);
//Normalize MoveVector if magnitude>1 ie to adjust the speed in diagonal motion
MoveVector=Vector3.Normalize(MoveVector);
//Multiply MoveVector by MoveSpeed
MoveVector*=MoveSpeed();
//Reapply VeticalVelocity to MoveVector.y
MoveVector=new Vector3(MoveVector.x,VerticalVelocity,MoveVector.z);
//Apply Gravity
ApplyGravity();
//Move character in world space
Controller.CharacterController.Move(MoveVector*Time.deltaTime);
}
This is the moving functionality for the third person shooter…