- Home /
Question by
melomikeboi · Apr 19, 2019 at 07:06 PM ·
3dcharactercharactercontrollercharacter movement
I cant move my character,My character wont move
Hi, Can somebody please help with this problem, my character wont move. I will include a screenshot and my c# code Please try to fix this!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class player : MonoBehaviour {
public Animator playerAnim;
private Rigidbody rbody;
private float moveSpeed;
// Start is called before the first frame update
void Start()
{
playerAnim = GetComponent<Animator>();
rbody = GetComponent<Rigidbody>();
moveSpeed = 5000f;
}
// Update is called once per frame
void Update()
{
float walkInput = Input.GetAxis("Horizontal");
//Walking Right//
if(walkInput > 0f)
{
playerAnim.SetBool("walking", true);
transform.rotation = Quaternion.Euler(0f, walkInput*-90f,0f);
rbody.AddForce(moveSpeed*walkInput*Time.deltaTime,0f,0f);
}
//walking left//
else if(walkInput < 0f)
{
playerAnim.SetBool("walking", true);
transform.rotation = Quaternion.Euler(0f, walkInput*-90f, 0f);
rbody.AddForce(moveSpeed*walkInput*Time.deltaTime,0f,0f);
}
else
{
playerAnim.SetBool("walking", false);
transform.rotation = Quaternion.Euler(0f,0f,0f);
}
}
}
Thanks -MeloMike
screenshotofunityieedtofixproblemlol.jpg
(132.2 kB)
Comment