I’m currently making a small 2.5D platformer as part of a college project, and I want to use the scripts I made from another prototype I made. I made the character, texture, a simple pixel background and a couple of animations, but I can’t seem to get the triggers to work to move the player and for the animations to work properly. I’ve looked back at my previous prototype to see if everything matches up in the animation’s parametres, the console hasn’t given me any errors, I’ve put the Animation Controller in the correct box in the Inspector etc. but they aren’t working. I’m not sure what I’m overlooking. The isGrounded tick box doesn’t get marked either. Nor the Jumped box in the Inspector, so these triggers aren’t working for some reason.
This is the PlayerController script I have:
public class PlayerController : MonoBehaviour
{
public Animator anim;
public float moveSpeed;
public float jumpForce;
public bool jumped;
public float gravityScale;
public float knockBackForce;
public float knockBackTime;
public float invincibilityLength;
private float jumpDelay;
private Vector3 moveDirection;
private float knockBackCounter;
private float invincibilityCounter;
private CharacterController controller;
void Start()
{
Cursor.visible = false;
controller = GetComponent<CharacterController>();
jumped = false;
if(jumpDelay <= 0)
{
jumpDelay = 5;
}
}
void Update()
{
if (knockBackCounter <= 0)
{
float moveHorizontal = Input.GetAxis("Horizontal");
moveDirection = new Vector3(moveHorizontal * moveSpeed, moveDirection.y);
if (moveHorizontal > 0)
{
transform.eulerAngles = new Vector3(0, 90);
}
else if (moveHorizontal < 0)
{
transform.eulerAngles = new Vector3(0, -100);
}
if (controller.isGrounded)
{
moveDirection.y = -1f;
if (Input.GetKey(KeyCode.KeypadPlus))
{
moveDirection.y = jumpForce;
jumped = true;
StartCoroutine(SpamBlockco());
}
}
}
else
{
knockBackCounter -= Time.deltaTime;
}
moveDirection.y = moveDirection.y + (Physics.gravity.y * gravityScale * Time.deltaTime);
controller.Move(moveDirection * Time.deltaTime);
anim.SetBool("isGrounded", controller.isGrounded);
anim.SetFloat("Speed", (Mathf.Abs(Input.GetAxis("Horizontal"))));
}
public void Knockback(Vector3 direction)
{
knockBackCounter = knockBackTime;
moveDirection = direction * knockBackForce;
moveDirection.y = knockBackForce;
}
public IEnumerator SpamBlockco()
{
if (moveDirection.y == jumpForce)
{
yield return new WaitForSeconds(jumpDelay);
}
yield return null;
jumped = false;
}
}
Here are some screenshots to compare the two. Some things I haven’t enabled or bothered with as I don’t believe they’re important at the moment. But correct me if I’m wrong. I don’t have a run animation yet as I haven’t made it.