Hi
My character has a Rigidbody and Character Controller attached. When the character walks off a building or incline it will continue to hold its position in the Y axis until the walk key is released. So when the model is moving forward it will not drop till its horizontal motion is zero. Anybody have something similar?
So I put my character in a fresh scene and went through the setup. This time gravity was handled differently: the model would not fall unless it had forward motion (exactly the opposite of my main scene). I then opened the Unity locomotion starter kit , applied a character controller to the default character and it works perfectly. Here is the starter kit script.
/// <summary>
///
/// </summary>
using UnityEngine;
using System;
using System.Collections;
[RequireComponent(typeof(Animator))]
//Name of class must be name of file as well
public class LocomotionPlayer : MonoBehaviour {
protected Animator animator;
private float speed = 0;
private float direction = 0;
private Locomotion locomotion = null;
// Use this for initialization
void Start ()
{
animator = GetComponent<Animator>();
locomotion = new Locomotion(animator);
}
void Update ()
{
if (animator Camera.main)
{
JoystickToEvents.Do(transform,Camera.main.transform, ref speed, ref direction);
locomotion.Do(speed * 6, direction * 180);
}
}
}
Here is the script from my main scene:
using UnityEngine;
using System.Collections;
public class IdleRunJumpAudio : MonoBehaviour {
protected Animator animator;
public float DirectionDampTime = .25f;
public bool ApplyGravity = true;
public AudioClip roar;
public AudioClip breath;
public AudioClip Attack;
// Use this for initialization
void Start ()
{
animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update ()
{
float h = Input.GetAxis("Horizontal"); // setup h variable as our horizontal input axis
float v = Input.GetAxis("Vertical"); // setup v variables as our vertical input axis
animator.SetFloat("Speed", v); // set our animator's float parameter 'Speed' equal to the vertical input axis
animator.SetFloat("Direction", h); // set our animator's float parameter 'Direction' equal to the horizontal input axis
if (animator)
{
AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);
if (stateInfo.IsName("Base Layer.Run"))
{
if (Input.GetButton("Fire1")) animator.SetBool("Jump", true);
}
else
{
animator.SetBool("Jump", false);
}
if(Input.GetKeyDown("r"))
{
animator.SetBool("Roar", !animator.GetBool("Roar"));
audio.PlayOneShot(roar);
}
else
{
animator.SetBool("Roar", false);
}
if(Input.GetKeyDown("t"))
{
animator.SetBool("Slash", !animator.GetBool("Slash"));
audio.PlayOneShot(Attack);
}
else
{
animator.SetBool("Slash", false);
}
}
}
}