Hi all
I am trying to make an RPG and currently am figuring out all the movement and animation scripting. (using Unity 5.5.1f1)
I have multiple animations (idle, walking, running, jumping) and have already connected all the animations with triggers and booleans (however I can change these if need be).
The problem I have is that I can’t create a difference in speed when walking and running.
This is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PaladinControls : MonoBehaviour {
static Animator anim;
public float speed = 5.0F;
public float rotationSpeed = 300.0F;
public float sprintSpeed = 100.0F;
public Rigidbody Paladin;
// Use this for initialization
void Start ()
{
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update() {
//Paladin.GetComponent<Rigidbody>();
//Paladin.velocity = new Vector3(speed * sprintSpeed, Paladin.velocity.y, Paladin.velocity.z);
float translation = Input.GetAxis("Vertical") * speed;
float rotation = Input.GetAxis("Horizontal") * rotationSpeed;
translation *= Time.deltaTime;
rotation *= Time.deltaTime;
transform.Translate(0, 0, translation);
transform.Rotate(0, rotation, 0);
if (translation == 0)
{
if (Input.GetButtonDown("Jump"))
{
anim.SetTrigger("isJumping");
}
}
if (translation != 0)
{
anim.SetBool("isWalking", true);
if (Input.GetButtonDown("Jump"))
{
anim.SetTrigger("isJumping");
}
if (Input.GetKeyDown(KeyCode.LeftShift))
{
Paladin.GetComponent<Rigidbody>();
//Paladin.velocity = new Vector3(Paladin.velocity.x, 0, 0);
anim.SetBool("isRunning", true);
if (Input.GetButtonDown("Jump"))
{
anim.SetTrigger("isJumping");
}
}
if (Input.GetKeyUp(KeyCode.LeftShift))
anim.SetBool("isRunning", false);
speed = 1.750F;
}
else
{
anim.SetBool("isWalking", false);
}
}
}
I have parts commented out because the character just slides to the right if I have them in effect.
I used this video
to make my code, and made some adjustments (running) to my liking.
How can I change it so it works with idle, walking, running and jumping, and have different speeds for walking and running (and idle is still).
Thanks