1. Add the role Controller component to the role, and then use the following code to control the role move and jump
Float Speed = 6.0f; float Jumpspeed = 8.0f; Float Gravity = 20.0f; Private Vector3 movedirection = Vector3.zero; void Start () { //gameobject.rigidbody = false; } void Update () { Charactercontroller controller = getcomponent<charactercontroller> (); if (controller.isgrounded) { movedirection =new Vector3 (Input.getaxis ("horizontal"), 0, Input.getaxis (" Vertical ")); Allows for player input movedirection = transform. Transformdirection (movedirection); How-to -move movedirection *= speed,//how fast to move if (Input.getbutton ("Jump")) { MOVEDIRECTION.Y = jumpspeed; } } Apply Gravity MOVEDIRECTION.Y-= gravity * time.deltatime; Move the controller controller. Move (movedirection * time.deltatime); }
2. Character subsidence after adding a role controller