Added cube movement

This commit is contained in:
gmanandmarbles 2023-07-31 18:39:27 -06:00
parent 30367b3c3e
commit c4cc829da3
2 changed files with 24 additions and 0 deletions
3D/Movement/Basic Cube

View file

@ -0,0 +1,19 @@
using UnityEngine;
public class CubeMovement : MonoBehaviour
{
public float movementSpeed = 5f;
void Update()
{
// Get input from keyboard or arrow keys
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
// Calculate the movement direction
Vector3 movementDirection = new Vector3(horizontalInput, 0f, verticalInput).normalized;
// Move the cube based on the input and movement speed
transform.Translate(movementDirection * movementSpeed * Time.deltaTime);
}
}

View file

@ -0,0 +1,5 @@
To use this script, follow these steps:
In Unity, create a 3D cube GameObject by going to GameObject -> 3D Object -> Cube.
Attach the script to the cube GameObject by dragging and dropping the script onto the cube in the Hierarchy or using the `Add Component