Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

generic character controller with root motion and rigidboy

Discussion in 'Animation' started by Minsc, Dec 10, 2017.

  1. Minsc

    Minsc

    Joined:
    Dec 30, 2013
    Posts:
    39
    Hi there,

    I am looking to animate a generic character i.e humanoid or else which has root motion enabled and can jump using rigidbody.

    So this is my code for now, I know I have to handle the ground collision but for now just for jumping I have a problem is that just applying a force makes kind of a fast translation up and right then the character drops, while I want a curved motion for jump. I am thinking of a bezier curve to follow or some coroutine with changing velocity, is there a less complicated approach?

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class movement : MonoBehaviour {
    6.  
    7.     // Use this for initialization
    8.     void Start () {
    9.      
    10.     }
    11.  
    12.     // Update is called once per frame
    13.     void Update () {
    14.         if (Input.GetAxis("Horizontal") == 1) gameObject.GetComponent<Animator>().SetBool("walk", true);
    15.         if (Input.GetAxis("Horizontal") == 0) gameObject.GetComponent<Animator>().SetBool("walk", false);
    16.         if (Input.GetKeyDown(KeyCode.Space)) gameObject.GetComponent<Rigidbody>().AddForce(new Vector3(3000, 3000, 0),ForceMode.Force);
    17.     }
    18. }
    19.  
    upload_2017-12-10_8-51-34.png

    thanks for your help
     
  2. Minsc

    Minsc

    Joined:
    Dec 30, 2013
    Posts:
    39
    up plz