Question by
iamsabbir · Dec 29, 2019 at 03:12 PM ·
c#charactercontrolleranimator controllerwalkinganimation script
my 3d character is animating perfectly but character is not moving when walk
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);
}
}
screenshot-18.png
(281.5 kB)
Comment
I can find one error, when setting the velocity, you should not multiply the values by Time.deltaTime.
Your answer
Follow this Question
Related Questions
Animating in c# 1 Answer
MoveTowards is curving for no reason 0 Answers
How to crouch a FPS Controller? 2 Answers
Character's jumping mechanism stuck into something invisible 1 Answer
Jump over obstacles(runner game) by speech recognition 1 Answer