Hi I’m making a 3rd person platform shooter I have a character with idle, run and jump animations and i can run around but i cant rotate.
I have tried to fix this issue by adding to my script but in my additions I use SimpleMove so the jump stops working and for some reason the idle animation doesnt seem to work (ie my character is permanently running even when no keys are down ).
I will attach the scripts at the bottom but my Question is how could i blend the two scripts i have efficiently so my character rotates rather then side steps ?
Any help would be much appreciated.
// ThirdPersonWalker.js
// this script adds two things to the default FPS walker
// - It adds movement forward by holding down both mouse keys
// - and it adds auto animation changing between idle, walk and run
// After adding this script to your controller, drag the character model to Target
// standard running speed
var speed = 6.0;
// walk speed adjust both for your charcter so feet don't slide on ground
var walkSpeed = .8;
var rotateSpeed = 3.0;
var jumpSpeed = 8.0;
var gravity = 20.0;
var Character : Transform;
private var moveDirection = Vector3.zero;
private var grounded : boolean = false;
// a flag to determine idle vs walking/running (so animations do not get started over and over)
private var walking : boolean = false;
// a flag to init idle animation at beginning
private var startup : boolean = true;
// a flag to determine walking vs running
private var running : boolean = true;
function FixedUpdate(){
if (grounded) {
// We are grounded, so recalculate movedirection directly from axes
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
// if both mouse buttons are down, move forward
if (Input.GetMouseButton(0) && Input.GetMouseButton(1)){
moveDirection.z = 1;
}
moveDirection = transform.TransformDirection(moveDirection);
if(running == true){
moveDirection *= speed;
} else {
moveDirection *= walkSpeed;
}
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
// auto toggle between idle and walking animations - based on run / walk switch
if(Character){
// toggle between walk and run with <left shift> R
if(Input.GetKey(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.R)){
if(running == true) {
running = false;
if(walking == true) Character.animation.CrossFade("RunForward");
}
else {
running = true;
if(walking == true) Character.animation.CrossFade("WalkForward");
}
}
if(startup == true){
startup = false;
Character.animation.Play("Idle1");
}
if((moveDirection == Vector3.zero)&&(walking == true)){
walking = false;
Character.animation.CrossFade("Idle1");
} else {
if((moveDirection != Vector3.zero)&&(walking == false)){
walking = true;
if(running == true){
Character.animation.CrossFade("RunForward");
} else {
Character.animation.CrossFade("WalkForward");
}
}
}
}
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
var controller : CharacterController = GetComponent(CharacterController);
var flags = controller.Move(moveDirection * Time.deltaTime);
grounded = (flags & CollisionFlags.CollidedBelow) != 0;
}
@script RequireComponent(CharacterController)
I want to have something similar to this but on the script above
var controller : CharacterController = GetComponent(CharacterController);
transform.Rotate(0,Input.GetAxis("Horizontal") * rotateSpeed, 0);
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed =speed * Input.GetAxis ("Vertical");
controller.SimpleMove(forward * curSpeed);