- Home /
my character is animating perfectly but character is not moving when walk .
my character walking animation is working but character not changing the place. i watch this tutorial to make my project i do as shown in tutorial but at this stage i stuck ( https://www.youtube.com/watch?v=wdOk5QXYC6Y&t=1065s![alt text][1] ) here are my codes : i don't know what to do
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class move : MonoBehaviour
{
public Animator anim;
public Rigidbody rbody;
private float inputH;
private float inputV;
// Start is called before the first frame update
void Start()
{
anim = GetComponent<Animator>();
rbody = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
inputH = Input.GetAxis ("Horizontal");
inputV = Input.GetAxis ("Vertical");
anim.SetFloat("inputH", inputH);
anim.SetFloat("inputV", inputV);
float moveX = inputH*20f*Time.deltaTime;
float moveZ = inputV*50f*Time.deltaTime;
if(moveZ <= 0f){
moveX = 0f;
}
rbody.velocity = new Vector3(moveX,0f,moveZ);
}
}
hot-18.png
[1]: /storage/temp/150597-screens
Answer by julian_cruz · Jan 02, 2020 at 10:24 PM
Hi @iamsabbir, I've used your script in a blank project and my capsule is moving. I would like to point out that the magic numbers for the velocity such as 50f and 20f move my capsule quite slow. So I increased them to 150f and 100f to see the capsule moving in a cube.
Can you check what values have this or attach your project to help you with it? new Vector3(moveX,0f,moveZ);