Bien sûr, voici un script simple pour déplacer un personnage en vue à la première personne (FPS) dans Unity :

csharp

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FPSController : MonoBehaviour
{
    public float moveSpeed = 5.0f;
    public float sensitivity = 2.0f;
    public float jumpHeight = 2.0f;
    
    private float moveFB;
    private float moveLR;
    private float rotX;
    private float rotY;
    private Vector3 movement;
    
    private CharacterController charController;
    
    void Start()
    {
        charController = GetComponent<CharacterController>();
        Cursor.lockState = CursorLockMode.Locked;
    }
    
    void Update()
    {
        // mouvement avant-arrière
        moveFB = Input.GetAxis("Vertical") * moveSpeed;
        // mouvement gauche-droite
        moveLR = Input.GetAxis("Horizontal") * moveSpeed;
        // rotation gauche-droite
        rotX = Input.GetAxis("Mouse X") * sensitivity;
        // rotation haut-bas
        rotY -= Input.GetAxis("Mouse Y") * sensitivity;
        rotY = Mathf.Clamp(rotY, -90.0f, 90.0f);
        
        movement = new Vector3(moveLR, 0, moveFB);
        movement = transform.rotation * movement;
        
        // saut
        if (Input.GetButtonDown("Jump"))
        {
            movement.y = Mathf.Sqrt(jumpHeight * -2.0f * Physics.gravity.y);
        }
        
        // appliquer gravité
        movement.y += Physics.gravity.y * Time.deltaTime;
        
        // rotation de la caméra
        transform.eulerAngles = new Vector3
spam fails_task lang_mismatch pii not_appropriate hate_speech sexual_content quality toxicity humor helpfulness creativity violence