This is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
[Header("Movement")]
public float MoveSpeed;
public Transform orientation;
float HorizontalInput;
float VerticalInput;
Vector3 MoveDirection;
Rigidbody rb;
private void start()
{
rb = GetComponent<Rigidbody>();
rb.freezeRotation = true;
}
private void update()
{
MyInput();
}
private void FixedUpdate()
{
MovePlayer();
}
private void MyInput()
{
HorizontalInput = Input.GetAxisRaw("Horizontal");
VerticalInput = Input.GetAxisRaw("Vertical");
}
private void MovePlayer()
{
//Calculate Movement Direction
MoveDirection = orientation.foward * VerticalInput + orientation.right * HorizontalInput;
rb.AddForce(MoveDirection.normalized * MoveSpeed * 10f, ForceMode.Force);
}
}
FAQ :
What are the guidelines for writing good questions?
–
We want Unity Answers to become a comprehensive database of questions and answers related to Unity. When you ask your questions, it can be helpful to keep a few things in mind:
–
Don’t write things that will be irrelevant in a few days. Writing that “This is urgent!” will probably not get you faster answers, but it may make people frown at your question.
–
Some reasons for getting a post rejected:
There exists duplicate questions with answers if you were to do a search, either on Answers or on the Forum or on Unity's tutorials
Your question isn't specific enough: asking for a script, asking multiple questions in one post or asking a question that could be either subjective or require extensive discussion