Search Unity

HELP with climbing animation

Discussion in 'Physics' started by jshahstudio, Oct 20, 2020.

  1. jshahstudio

    jshahstudio

    Joined:
    Oct 20, 2020
    Posts:
    1
    Hello all,

    I am trying to get a humanoid character to climb up a wall with specific targets, kind of like rock climbing. I have no clue how to go about having the character's limbs correspond to the keyboard inputs. Please help. this is what I have:



    using System.Collections;
    using System.Collections.Generic;
    using UnityEditor.UIElements;
    using UnityEngine;
    using UnityEngine.XR;

    public class Ugh : MonoBehaviour
    {
    public GameObject player;
    public GameObject RightHand;
    public GameObject LeftHand;
    public GameObject LeftFoot;
    public GameObject RightFoot;
    private Animator animator;

    float speed = 3;
    //public GameObject target;

    [SerializeField] Transform target = null;

    [SerializeField] AvatarIKGoal goal = AvatarIKGoal.LeftHand;

    [Range(0, 1)]
    [SerializeField] float weight = 0.5f;

    void Start()
    {
    animator = this.GetComponent<Animator>();

    }

    private void OnAnimatorIK(int layerIndex)
    {
    animator.SetIKPosition(AvatarIKGoal.LeftHand, target.transform.position);
    animator.SetIKPositionWeight(AvatarIKGoal.LeftHand, 0.5f);

    animator.SetLookAtPosition(target.transform.position);
    animator.SetLookAtWeight(0.5f, 0.5f, 0.5f, 0.5f);
    }
    // Update is called once per frame
    void Update()
    {
    if (Input.GetAxis("Vertical") !=0)
    {
    player.transform.Translate(Vector3.up * Input.GetAxis("Vertical") * Time.deltaTime);

    }

    if (Input.GetAxis("Horizontal") != 0)
    {
    player.transform.Translate(Vector3.right * Input.GetAxis("Horizontal") * Time.deltaTime);

    }
    //this.transform.Translate(this.transform.forward * speed * Time.deltaTime, Space.World);
    //animator.SetFloat("speed", speed);
    }
    }