Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

how to make your player movr the way you are rotated in unity

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

public class mouse : MonoBehaviour
{
    public float sensX;
    public float sensY;

    public Transform orientation;

    float xRotation;
    float yRotation;

    private void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;
        Cursor.visible = false;

    }
    private void Update()
    {
        float mouseX = Input.GetAxisRaw("Mouse X") * Time.deltaTime * sensX;
        float mouseY = Input.GetAxisRaw("Mouse Y") * Time.deltaTime * sensY;

        yRotation += mouseX;
        xRotation -= mouseY;
        xRotation = Mathf.Clamp(xRotation, -90f, 90f);

        transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
        orientation.rotation = Quaternion.Euler(0, yRotation, 0);
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# date to julian YYJJJ date 
Csharp :: get path revit linked unload 
Csharp :: Library dll unless netloaded by AutoCAD 
Csharp :: c# download to string 
Csharp :: unity torque distance joint 
Csharp :: .net 6 foreach only if not null 
Csharp :: how to read reportview query string asp.net c# 
Csharp :: change character velocity unity 
Csharp :: Propertychanged is not firing up when text is change 
Csharp :: use & symbole in xml as a text using c# 
Csharp :: c# open config file by path 
Csharp :: c# place all keys in dictionary into array 
Csharp :: localhost ssl certificate error in visual studio 2022 .net 6 
Csharp :: c# please build the project and retry 
Csharp :: C# predict rotation by an angular velocity 
Csharp :: All and Any linq c# examlpe replace 
Csharp :: C# program applies bonus points 
Csharp :: unity3d spin wheel 
Csharp :: C# create delegate type at runtime 
Csharp :: unity make particles stay still 
Csharp :: unity button text changes when clicked 
Csharp :: c# url relative path remove 
Csharp :: how to get connection string from xml file in c# 
Csharp :: C# today, yesterday, last week, last month 
Csharp :: c# distinct dictionary 
Csharp :: unity c# bool to int conversion 
Csharp :: c# loop back 
Csharp :: C# String Manipulation: 
Csharp :: c# arraylist to listview 
Csharp :: how to use K2 games Games parallax background 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =