Answer the question
In order to leave comments, you need to log in
unity. C#. The character moves globally, but it should be local. How to do it?
I'm making a game in first person, but when the character is rotated, `Player.transform.Translate` moves it globally. Tried through rigidbody, but did not help. How to fix it?
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
[Header("Player")]
public GameObject Player;
[Header("Move")]
public bool Move;
public float MoveSpeed;
private Vector3 MoveDir;
private float PlayerSpeed;
[Header("Run")]
public bool Run;
public float RunSpeed;
[Header("Jump")]
public bool Jump = true;
public float JumpForce = 4f;
[HideInInspector] public bool IsGround;
void Awake() {
if (!Move) {
MoveSpeed = 0;
}
if (!Run) {
RunSpeed = MoveSpeed;
}
}
private void FixedUpdate() {
float Horizontal = Input.GetAxis("Horizontal");
float Vertical = Input.GetAxis("Vertical");
if (Input.GetAxis("Fire3") == 0) {
PlayerSpeed = MoveSpeed;
}
if (Input.GetAxis("Fire3") > 0) {
PlayerSpeed = RunSpeed;
}
MoveDir = new Vector3(Horizontal * PlayerSpeed, 0f, Vertical * PlayerSpeed);
Player.transform.Translate(MoveDir);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question