-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerControllerTwo.cs
More file actions
75 lines (50 loc) · 2.3 KB
/
Copy pathPlayerControllerTwo.cs
File metadata and controls
75 lines (50 loc) · 2.3 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerControllerTwo : MonoBehaviour {
public Transform target;
private float noTurn = 0.1f;
private float factor = 150.0f;
private Vector3 center;
private Vector3 ship;
public int shipSpeed;
public int shipMaxSpeed;
private float distanceToFollow;
private float shipRotX;
private float shipRotY;
// Use this for initialization
void Start () {
center = new Vector3(Screen.width / 2, Screen.height / 2, 0);
}
// Update is called once per frame
void Update() {
float speed = 0.2f;
Vector3 delta = (Input.mousePosition - center) / Screen.height;
Debug.Log(delta);
shipRotX += Input.GetAxis("Mouse X") * 0.20f;
shipRotY += Input.GetAxis("Mouse Y") * 0.20f;
ship.x = shipRotX;
ship.y = shipRotY;
if (delta.y > noTurn)
transform.Rotate((delta.y + noTurn) * Time.deltaTime * factor, 0, 0);
if (delta.y < -noTurn)
transform.Rotate((delta.y - noTurn) * Time.deltaTime * factor, 0, 0);
if (delta.x > noTurn)
transform.Rotate(0, (delta.x - noTurn) * Time.deltaTime * factor, 0);
if (delta.x < -noTurn)
transform.Rotate(0, (delta.x + noTurn) * Time.deltaTime * factor, 0);
/*if (Input.mousePosition.x == 0.0 && Input.mousePosition.y == 0.0)
{
//transform.GetChild(1).Rotate(-ship.normalized * .015f * (ship.sqrMagnitude + 500) * (1 + speed / shipMaxSpeed) * Time.fixedDeltaTime);
}*/
/*ship -= ship.normalized * ship.sqrMagnitude * .08f * Time.fixedDeltaTime;
transform.GetChild(1).Rotate(ship * Time.fixedDeltaTime);*/
transform.GetChild(0).Rotate(shipRotY, shipRotX, 0);
shipRotY *= 0.9f;
shipRotX *= 0.9f;
float sqrOffset = transform.GetChild(0).localPosition.sqrMagnitude;
Vector3 offsetDir = transform.GetChild(0).localPosition.normalized;
transform.GetChild(0).Translate(-offsetDir * sqrOffset * 20 * Time.fixedDeltaTime);
transform.Translate(-(offsetDir * sqrOffset * 50 + transform.GetChild(0).forward * shipSpeed) * Time.fixedDeltaTime, Space.World);
}
}