Question by
ErikReichenbach · Sep 30, 2018 at 03:20 AM ·
animationmovement scriptplayer movementsynchronization
Sync Anima2D Animations with Player Movement
Hi there, looking for help syncing my saved Animations from Anima2d with my player controller. Here is my 3D Player Movement script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour {
public float speed = 6.0F;
public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
private Vector3 moveDirection = Vector3.zero;
void Update() {
CharacterController controller = GetComponent<CharacterController>();
if (controller.isGrounded) {
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton("Jump"))
moveDirection.y = jumpSpeed;
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
}
Essentially, I would like it so the animation sequence for,"Walk Right" plays when the player moves right.
Currently, only Idle Animation plays when the character does anything in the 3d space. I am attempting to add animations that activate on jump, on left movement, on right movement, etc. without much success.
I am an artist that has only recently started learning this, so please help me understand a method to do this, or refer me to an online tutorial that may be of some help. In the past I have asked for help and was met with,"Here's the Scripting Unity Guide link" which is extremely unhelpful.
Thank you!
Comment