Je suis en train de configurer un blend tree, qui fonctionne bien, à un petit détail près.
J'y ai inclus l'animation de marche (X 0 - Y 0.5) et l'animation de course (X 0 - Y 1).
Le problème du clavier c'est que lorsque j'appuie sur ma touche, la float passe de 0 à 1 et donc, je ne peux pas jouer mon animation de marche.
https://image.noelshack.com/fichiers/20 ... ndtree.png
J'ai également tenté de faire 2 blend tree différents (1 pour la marche, 1 pour la course) en switchant de l'un à l'autre avec avec une bool (run true, run false). En soit ça fonctionne, mais le résultat n'est pas super
je voudrai savoir si il existe un moyen de limiter les floats (vertical et horizontal) (-0.5 et 0.5 max) et de faire sauter cette limite en appuyant sur une touche (Left Shift) afin d'activer l'animation de course ?
Voici ce que j'ai en code pour le moment:
Code : Tout sélectionner
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMotor : MonoBehaviour
{
public float walkSpeed = 3f;
public float runSpeed = 8f;
public float turnSpeed = 180f;
Animator anim;
void Start()
{
anim = GetComponent<Animator>();
}
void Update()
{
if (!Input.GetKey(KeyCode.LeftShift))
{
anim.SetFloat("vertical", Input.GetAxis("Vertical"));
anim.SetFloat("horizontal", Input.GetAxis("Horizontal"));
transform.Translate(Vector3.forward * Input.GetAxis("Vertical") * walkSpeed * Time.deltaTime);
transform.Translate(Vector3.right * Input.GetAxis("Horizontal") * walkSpeed * Time.deltaTime);
transform.Rotate(Vector3.up * Input.GetAxis("Mouse X") * turnSpeed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.LeftShift))
{
anim.SetFloat("vertical", Input.GetAxis("Vertical"));
anim.SetFloat("horizontal", Input.GetAxis("Horizontal"));
transform.Translate(Vector3.forward * Input.GetAxis("Vertical") * runSpeed * Time.deltaTime);
transform.Translate(Vector3.right * Input.GetAxis("Horizontal") * runSpeed * Time.deltaTime);
transform.Rotate(Vector3.up * Input.GetAxis("Mouse X") * turnSpeed * Time.deltaTime);
}
}
}
Bonne journée.