-
Notifications
You must be signed in to change notification settings - Fork 450
/
Copy pathPlayerMovement.cs
41 lines (31 loc) · 1.12 KB
/
PlayerMovement.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using UnityEngine;
using System.Collections.Generic;
using System.Collections;
//Script for moving a gameObject smoothly
//Usage: Attach the character controller component to the gameobject that you want to move
namespace UnityLibary
{
public class PlayerMovement : MonoBehaviour
{
// place the gameobject that you want to move to the controller placeholder
public CharacterController controller;
public float speed = 5f;
void Update()
{
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 move = transform.right * x + transform.forward * z;
controller.Move(move * speed * Time.deltaTime);
//Rotate clockwise
if (Input.GetKey(KeyCode.E))
{
transform.RotateAround(transform.position, Vector3.up, 100 * Time.deltaTime);
}
// Rotate anticlockwise
if (Input.GetKey(KeyCode.Q))
{
transform.RotateAround(transform.position, -Vector3.up, 100 * Time.deltaTime);
}
}
}
}