using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RbMovement : MonoBehaviour
{
[Header("Movement")]
public float moveSpeed = 6f;
public float movementMultiplier = 10f;
float rbDrag = 6f;
float horizontalMovement;
float verticalMovement;
Vector3 moveDirection;
Rigidbody rb;
private void Start()
{
rb = GetComponent<Rigidbody>();
rb.freezeRotation = true;
}
private void Update()
{
MyInput();
}
void MyInput()
{
horizontalMovement = Input.GetAxisRaw("Horizontal");
verticalMovement = Input.GetAxisRaw("Vertical");
moveDirection = transform.forward * verticalMovement + transform.right * horizontalMovement;
}
void ControlDrag()
{
rb.drag = rbDrag;
}
private void FixedUpdate()
{
MovePlayer();
}
void MovePlayer()
{
rb.AddForce(moveDirection * moveSpeed, ForceMode.Acceleration);
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter