Question by
RA7x · Oct 19, 2020 at 09:35 AM ·
charactercontrollermovement scriptplayer movementcheckchecking
,Please help me with CharacterController.isGrounded
Could You PLEASE tell me where is my problem in this code
I'm trying to move my player when he's Grounded only , Otherwise Not so I wrote this
||
\\ //
\/
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerMovement : MonoBehaviour {
CharacterController controller;
public float speed = 5f;
float zAxis;
float xAxis;
// Start is called before the first frame update
void Start()
{
controller = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update()
{
if (controller.isGrounded)
{
// Taking Inputs From User //
zAxis = Input.GetAxis("Horizontal");
xAxis = Input.GetAxis("Vertical");
// Adding Speed Controll //
zAxis *= speed;
xAxis *= speed;
// Adding Time.deltaTime //
zAxis *= Time.deltaTime;
xAxis *= Time.deltaTime;
// Adding Movement To Player //
transform.Translate(xAxis, 0.0f, zAxis);
}
}
} ,Could You PLEASE tell me where is my problem in this code
I'm trying to move my player when he's Grounded only , Otherwise Not so I wrote this
||
\\ //
\/
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerMovement : MonoBehaviour {
CharacterController controller;
public float speed = 5f;
float zAxis;
float xAxis;
// Start is called before the first frame update
void Start()
{
controller = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update()
{
if (controller.isGrounded)
{
// Taking Inputs From User //
zAxis = Input.GetAxis("Horizontal");
xAxis = Input.GetAxis("Vertical");
// Adding Speed Controll //
zAxis *= speed;
xAxis *= speed;
// Adding Time.deltaTime //
zAxis *= Time.deltaTime;
xAxis *= Time.deltaTime;
// Adding Movement To Player //
transform.Translate(xAxis, 0.0f, zAxis);
}
}
}
Comment