forked from HussainAther/spacevrcontrast
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerController.cs
More file actions
51 lines (42 loc) · 1.36 KB
/
PlayerController.cs
File metadata and controls
51 lines (42 loc) · 1.36 KB
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
42
43
44
45
46
47
48
49
50
51
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
[RequireComponent(typeof(Rigidbody))]
public class Boundary
{
public float xMin, xMax, zMin, zMax;
}
public class PlayerController : MonoBehaviour
{
public Rigidbody rb;
public float speed = 15f;
public float maxSpeed = 25f;
private Vector3 position;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement.position = new Vector3(moveHorizontal, 0f, moveVertical);
float minX = Camera.main.ViewportToWorldPoint(new Vector3(0, 0, 0)).x;
float maxX = Camera.main.ViewportToWorldPoint(new Vector3(1, 0, 0)).x;
if (transform.position.x < minX || transform.position.x > maxX)
{
rb.velocity = 0;
}
else
{
if (rb.velocity.magnitude < maxSpeed) { rb.velocity += movement * speed * Time.deltaTime; }
}
if (rb.velocity.magnitude < maxSpeed){rb.velocity += movement * speed * Time.deltaTime;}
{
Mathf.Clamp(movement.position.x, Boundary.xMin, Boundary.xMax);
0.0f;
Mathf.Clamp(movement.position.z, Boundary.zMin, Boundary.zMax);
};
}
}