-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlayerController.cs
115 lines (96 loc) · 3.22 KB
/
PlayerController.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float speed;
private Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
// Invert the z and w of the gyro attitude
Quaternion rotFix = new Quaternion(Input.gyro.attitude.x, Input.gyro.attitude.y, -Input.gyro.attitude.z, -Input.gyro.attitude.w);
// Now set the local rotation of the child camera object
transform.localRotation = rotFix;
//Walk "forward" in direction that camera is pointing
float distance = 1.0F;
Vector3 new_position = transform.position + transform.forward * distance * Time.deltaTime;
float MIN_X = -8.0F;
float MAX_X = 8.0F;
float MIN_Y = 1.0F;
float MAX_Y = 5.0F;
float MIN_Z = -8.0F;
float MAX_Z = 8.0F;
transform.position = new Vector3(
Mathf.Clamp(new_position.x, MIN_X, MAX_X),
Mathf.Clamp(new_position.y, MIN_Y, MAX_Y),
Mathf.Clamp(new_position.z, MIN_Z, MAX_Z));
// transform.position = new_position;
// float moveHorizontal = Input.GetAxis("Horizontal");
// float moveVertical = Input.GetAxis("Vertical");
//
// Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
//rb.AddForce(movement * speed);
rb.AddForce(transform.position * speed);
}
// void FixedUpdate()
// {
// float moveHorizontal = Input.GetAxis("Horizontal");
// float moveVertical = Input.GetAxis("Vertical");
//
// Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
//
// rb.AddForce(movement * speed);
// }
// void Start()
// {
// camParent = new GameObject("CamParent");
// Input.gyro.enabled = true;
//
// camParent.transform.position = transform.position;
// transform.parent = camParent.transform;
//
// // Rotate the parent object by 90 degrees around the x axis
// camParent.transform.Rotate(Vector3.right, 90);
//
// transform.position = new Vector3(0, 1, 0);
// }
//
// void Update()
// {
// // Invert the z and w of the gyro attitude
// Quaternion rotFix = new Quaternion(Input.gyro.attitude.x, Input.gyro.attitude.y, -Input.gyro.attitude.z, -Input.gyro.attitude.w);
//
// // Now set the local rotation of the child camera object
// transform.localRotation = rotFix;
//
// //Walk "forward" in direction that camera is pointing
//
// float distance = 1.0F;
// Vector3 new_position = transform.position + transform.forward * distance * Time.deltaTime;
//
// float MIN_X = -8.0F;
// float MAX_X = 8.0F;
// float MIN_Y = 1.0F;
// float MAX_Y = 100.0F;
// float MIN_Z = -8.0F;
// float MAX_Z = 8.0F;
//
// transform.position = new Vector3(
// Mathf.Clamp(new_position.x, MIN_X, MAX_X),
// Mathf.Clamp(new_position.y, MIN_Y, MAX_Y),
// Mathf.Clamp(new_position.z, MIN_Z, MAX_Z));
//
// transform.position = new_position;
// }
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Pick Up"))
{
other.gameObject.SetActive(false);
}
}
}