TOP DOWN MOVEMENT IN UNITY 3D (TUTORIAL)

Поділитися
Вставка
  • Опубліковано 26 лис 2024

КОМЕНТАРІ • 4

  • @Alireza-t1x6h
    @Alireza-t1x6h Рік тому +1

    That was helpful ❤

  • @Ish.ntsharma
    @Ish.ntsharma Рік тому +1

    my man thank u so much

  • @gamedevleo5075
    @gamedevleo5075  2 роки тому +6

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class PlayerMovement : MonoBehaviour
    {
    public float moveSpeed;
    private Rigidbody myRigidbody;
    private Vector3 moveInput;
    private Vector3 moveVelocity;
    private Camera mainCamera;
    // Start is called before the first frame update
    void Start()
    {
    myRigidbody = GetComponent();
    mainCamera = FindObjectOfType();
    }
    // Update is called once per frame
    void Update()
    {
    moveInput = new Vector3(Input.GetAxisRaw("Horizontal"), 0f, Input.GetAxisRaw("Vertical"));
    moveVelocity = moveInput * moveSpeed;
    Ray cameraRay = mainCamera.ScreenPointToRay(Input.mousePosition);
    Plane groundPlane = new Plane(Vector3.up, Vector3.zero);
    float rayLenght;
    if (groundPlane.Raycast(cameraRay, out rayLenght))
    {
    Vector3 pointToLook = cameraRay.GetPoint(rayLenght);
    Debug.DrawLine(cameraRay.origin, pointToLook, Color.blue);
    transform.LookAt(new Vector3(pointToLook.x, transform.position.y, pointToLook.z));
    }
    }
    void FixedUpdate()
    {
    myRigidbody.velocity = moveVelocity;
    }
    }