Player gets stuck half way through the ground (Unity 2020)
Everything has Mesh Colliders and Trigger is unchecked. The empty GameObject renamed "Player" has the soldier as a child. The Player has the Character Controller which surrounds the child or soldier. Character Controller is supposed to also act as a collider. In Game Play mode the soldier drops and gets stuck half way through the road. See picture. Hopefully, someone can answer and describe a fix, and not leave me hanging until Unity wants another year's subscription for $1800 or I can tell Unity where to stick it.
We ain't yoda to read your $$anonymous$$d
Please post a code and we'll help.
Answer by J_Ripley · Nov 29, 2021 at 02:32 PM
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerMovement : MonoBehaviour { //Declaring variables private CharacterController characterController; private Animator animator; [SerializeField] private float moveSpeed = 100f; [SerializeField] private float turnSpeed = 5f;
// Start is called before the first frame update
private void Awake()
{
characterController = GetComponent<CharacterController>();
animator = GetComponentInChildren<Animator>();
}
// Update is called once per frame
private void Update()
{
var horizontal = Input.GetAxis("Horizontal");
var vertical = Input.GetAxis("Vertical");
var movement = new Vector3(horizontal, 0, vertical);
characterController.SimpleMove(movement * Time.deltaTime * moveSpeed);
animator.SetFloat("Speed", movement.magnitude);
if (movement.magnitude > 0)
{
Quaternion newDirection = Quaternion.LookRotation(movement);
transform.rotation = Quaternion.Slerp(transform.rotation, newDirection, Time.deltaTime * turnSpeed);
}
}
}