Hi!
I am developing a 2D adventure game in Adventure Creator. I created a "platformer" controls script. (W = jump, AS = left, right).
using UnityEngine;
public class PlayerScript : PhysicsObject {
public float maxSpeed = 7;
public float jumpTakeOffSpeed = 7;
bool running;
private SpriteRenderer spriteRenderer;
private Animator animator;
private Char acCharacter;
void Start()
{
acCharacter = GetComponent<Char>();
}
void Awake ()
{
spriteRenderer = transform.GetChild(0).GetComponent<SpriteRenderer> ();
animator = transform.GetChild(0).GetComponent<Animator> ();
}
protected override void ComputeVelocity()
{
Vector2 move = Vector2.zero;
if (Input.GetButtonDown ("Jump") && grounded) {
velocity.y = jumpTakeOffSpeed;
} else if (Input.GetButtonUp ("Jump"))
{
if (velocity.y > 0) {
velocity.y = velocity.y * 0.5f;
}
}
targetVelocity = move * maxSpeed;
}
}
Now I need to attach animations at the main character. I do not know how to do that at all, because I am a beginner. I could do it using classic unity animator transitions, but I am just wondering, if it isnt some easier way to do animations using AC.
Thank you for the respond!
VS
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
AC can be used to auto-play animations on a character if it is also controlling his motion - since it then knows what direction he's facing, his speed, etc. A custom motion system like the one above would have to also incorporate animation.
Set the Player's Animation engine to Sprites Unity Complex, and then clear all the text fields beneath it (MoveSpeed, etc).
Then define two float parameters in your Animator: xSpeed and ySpeed.
At the end of your ComputeVelocity function, add the following:
You should then find that the two parameters update to match the character's horiztonal and vertical speeds. You can create animator transitions / blend trees etc in your Animator to play different animations accordingly.
Please look to the general Unity forums for more advice on incorporating animations into your script, however - this isn't AC related.
Yes, so long as he relies on the Sprites Unity Complex engine, and you set the Action's Method to either Change Parameter Value or Play Custom.