hacklink al hack forum organik hit kayseri escort b-ok zeta library books z librarygrandpashabetistanbul escortsfixbetMegabahiszbahistipobetgamdombetciodinamobetsahabetbetmatik güncel girişbetsat güncel girişanal sex pornviagraanal sexmatbetvaycasinovaycasino girişbelugabahisbelugabahisvbetvbet girişkralbetbetebetbetgarantidinamobetalobetluxbet giriş

Post Details Page

At Devhq.in, we provide comprehensive digital solutions for businesses. From software development and app creation to social media management and brand design, we help you build and grow your digital presence.

Player 3D Movement With Camera Movement in Unity

I will explain how you can make a 3D Player movement in Unity

Make a New Input Action

I Setup my Character like this here i added camera if you want to remove then you can

CheckGround : I added a CheckGround Empty Object for checking character is touching ground or not.

📁PlayerMovement.cs
using System.Transactions;
using UnityEngine;
using UnityEngine.InputSystem;


[RequireComponent(typeof(CharacterController))]
public class PlayerController : MonoBehaviour
{
    [SerializeField]
    private InputActionReference movementControl;
    [SerializeField]
    private InputActionReference jumpControl;
    private CharacterController controller;
    private Vector3 playerVelocity;
    private bool groundedPlayer;
    [SerializeField]
    private float playerSpeed = 2.0f;
    [SerializeField]
    private float jumpHeight = 1.0f;
    [SerializeField]
    private float gravityValue = -9.81f;
    private Transform cameraMainTransform;
    private float rotationSpeed = 4.0f;

    private void OnEnable()
    {
        movementControl.action.Enable();
        jumpControl.action.Enable();
    }
    private void OnDisable()
    {
        movementControl?.action.Disable();
        jumpControl?.action?.Disable(); 
    }

    private void Start()
    {
        controller = gameObject.GetComponent<CharacterController>();
        cameraMainTransform = Camera.main.transform;
        Cursor.lockState = CursorLockMode.Locked;
    }

    void Update()
    {
        groundedPlayer = controller.isGrounded;
        if (groundedPlayer && playerVelocity.y < 0)
        {
            playerVelocity.y = 0f;
        }
        Vector2 movement = movementControl.action.ReadValue<Vector2>();
        Vector3 move = new Vector3(movement.x, 0, movement.y);
        move = cameraMainTransform.forward * move.z + cameraMainTransform.right * move.x;
        move.y = 0;
        controller.Move(move * Time.deltaTime * playerSpeed);

    
        // Changes the height position of the player..
        if (jumpControl.action.triggered && groundedPlayer)
        {
            playerVelocity.y += Mathf.Sqrt(jumpHeight * -3.0f * gravityValue);
        }

        playerVelocity.y += gravityValue * Time.deltaTime;
        controller.Move(playerVelocity * Time.deltaTime);

        if(movement!=Vector2.zero)
        {
            float targetAngle = Mathf.Atan2(movement.x,movement.y) * Mathf.Rad2Deg + cameraMainTransform.eulerAngles.y;
            Quaternion rotation = Quaternion.Euler(0f,targetAngle,0f);
            transform.rotation = Quaternion.Lerp(transform.rotation, rotation, Time.deltaTime*rotationSpeed);
        }
    }
}
C#

After writing this code you have to assign all Components in the variables

This is my Cinemachine Camera Settings

Share now :

Facebook
Twitter
LinkedIn
Review Your Cart
0
Add Coupon Code
Subtotal