Last active
December 11, 2015 07:38
-
-
Save anchan828/4567374 to your computer and use it in GitHub Desktop.
Animatorで重力
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
[RequireComponent(typeof(Animator))] | |
[RequireComponent(typeof(CharacterController))] | |
public class RobotController : MonoBehaviour | |
{ | |
private Animator animator; | |
private CharacterController characterController; | |
void Start () | |
{ | |
animator = GetComponent<Animator> (); | |
characterController = GetComponent<CharacterController> (); | |
} | |
void Update () | |
{ | |
animator.SetFloat ("run", Input.GetAxis ("Vertical")); | |
animator.SetFloat ("dir", Input.GetAxis ("Horizontal")); | |
} | |
private Vector3 gravityVelocity = Vector3.zero; | |
void OnAnimatorMove () | |
{ | |
Vector3 pos = animator.deltaPosition; | |
transform.rotation = animator.rootRotation; | |
if (characterController.isGrounded == false) { | |
pos += gravityVelocity += Vector3.down * animator.gravityWeight * Time.deltaTime; | |
} else { | |
gravityVelocity = Vector3.zero; | |
} | |
characterController.Move (pos); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment