Jump to content
Unity Insider Forum

Scripting einer Rückwärts-Bewegung PLUS Animation


wueschn

Recommended Posts

Werte Expertinnen und Experten

Ich habe zu Übungszwecken versucht, ein Model mit den Pfeiltasten zu steuern und zugleich zu jeder Richtung auch eine Laufanimation zuzuordnen (mittels Mechanim).

Was ich nicht schaffe, ist eine Running Animation rückwärts. Ich habe zwar eine Animation samt Script für rückwärts  laufen, weiß aber nicht, wie die Bewegung selbst scripten soll.

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AvatarControlling : MonoBehaviour
{
    private Animator anim;
    public float speed = 3.0f;
    public float rotationSpeed = 30.0f;


    void Start()
    {
        anim = GetComponent<Animator>();
    }

  
    void Update()
    {
        //moving forward/backward via ArrowKeys
        float translation = Input.GetAxis("Vertical");
        //turning left/right via ArrowKeys
        float rotation = Input.GetAxis("Horizontal") * rotationSpeed;
        translation = translation * Time.deltaTime * speed;
        rotation = rotation * Time.deltaTime;
        transform.Translate(0, 0, translation);
        transform.Rotate(0, rotation, 0);

       
        //left arrowKey starts a letMovement motion
        if (Input.GetKeyDown(KeyCode.LeftArrow))
        {

            anim.SetTrigger("isLeft");
        }
        //right arrowKey starts a rightMovement motion
        if (Input.GetKeyDown(KeyCode.RightArrow))
        {

            anim.SetTrigger("isRight");
        }

        //starts a jumping animation by space key
        if (Input.GetButtonDown("Jump"))
        {

            anim.SetTrigger("isJumping");
        }
        //starts a running animation forwards
        if(translation != 0)
        {

            anim.SetBool("isRunning", true);
        }
        else
        {

            anim.SetBool("isRunning", false);
        }
        //how to start the running back animation via translation??????


    }
}

Hat jemand eine Idee, wie ich meine Rückwärts-Laufen-Animation mit translation scripten kann??

 

Vielen Dank vorab

wueschn

Link zu diesem Kommentar
Auf anderen Seiten teilen

Archiviert

Dieses Thema ist jetzt archiviert und für weitere Antworten gesperrt.

×
×
  • Neu erstellen...