Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(+1)

Mon jeu est en 3D j'aimerais tester le character controller sur des personnages de mixamo

Le script de mon joueur: 

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class PlayerMovement : MonoBehaviour

{

    public CharacterController controller;

    public float speed = 12f;

    public float gravity = -9.81f;

    public float jumpHeight = 3f;

    public Animator walk;

    public Transform groundCheck;

    public float groundDistance = 0f;

    public LayerMask groundMask;

    AudioSource audiosource;

    Vector3 velocity;

    bool isGrounded;

    // Update is called once per frame

    void Update()

    {  

        isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);

        if(isGrounded && velocity.y < -20)

        {

            velocity.y = 0f;

        }

        float x = Input.GetAxis("Horizontal");

        float z = Input.GetAxis("Vertical");

        Vector3 move = transform.right * x + transform.forward * z;

        controller.Move(move * speed * Time.deltaTime);

        if (Input.GetButtonDown("Jump") && isGrounded)

        {

            velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);

        }

        velocity.y += gravity * Time.deltaTime;

        controller.Move(velocity * Time.deltaTime);

    }

}


Et celui pour bouger la tête :

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class MouseLook : MonoBehaviour

{

    public float mouseSensitivity = 100f;

    public Transform playerBody;

    float xRotation = 0f;

    // Start is called before the first frame update

    void Start()

    {

        Cursor.visible = false;

        Cursor.lockState = CursorLockMode.Locked;

    }

    // Update is called once per frame

    void Update()

    {

        float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;

        float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;

        xRotation -= mouseY;

        xRotation = Mathf.Clamp(xRotation, -90f, 90f);

        transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);

        playerBody.Rotate(Vector3.up * mouseX);

    }

}