Answer the question
In order to leave comments, you need to log in
How to fix a bug with player movement?
When I don't move the joystick, the arrow points down. When I move the joystick everything is fine, but as soon as I let go it immediately sticks to the ground. Help how to fix it? Maybe something is wrong with the model export?
Script:
public float speedMove;
public float gravityForce;
private Vector3 moveVector;
Vector3 direct;
private Jostic joystick;
void Start()
{
joystick = GameObject.FindGameObjectWithTag("Joystick").GetComponent<Jostic>();
}
// Update is called once per frame
void Update()
{
transform.rotation = Quaternion.LookRotation(direct);
CharterMove();
}
private void CharterMove()
{
moveVector = Vector3.zero;
moveVector.x = -joystick.Vertical() * speedMove;
moveVector.z = -joystick.Horizontal() * speedMove;
moveVector.y = gravityForce;
if (Vector3.Angle(Vector3.forward, moveVector) > 1f || Vector3.Angle(Vector3.forward, moveVector) < 0.0f)
{
direct = Vector3.RotateTowards(transform.forward, -moveVector, speedMove, 0f);
transform.rotation = Quaternion.LookRotation(direct);
}
else transform.rotation = Quaternion.LookRotation(direct);
GetComponent<CharacterController>().Move(moveVector * Time.deltaTime);
}
Answer the question
In order to leave comments, you need to log in
Assignment of gravity?
moveVector.y = gravityForce;
moveVector.y -= gravityForce;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question