-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathship_controls.cs
59 lines (51 loc) · 1.44 KB
/
ship_controls.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class ship_controls : MonoBehaviour
{
//Steering Objects
public Transform steeringWheel;
public GameObject Boat;
public Rigidbody BoatRigidBody;
public TextMeshPro debug;
public float currentSteeringWheelRotation = 0;
//Dampeners
public float turnDampening;
public GameObject Player;
public bool anchorDeployed;
// Start is called before the first frame update
void Start()
{
anchorDeployed = true;
}
// Update is called once per frame
void Update()
{
if (anchorDeployed == false)
{
turnShip();
}
currentSteeringWheelRotation = steeringWheel.transform.eulerAngles.y;
}
private void turnShip()
{
var turn = -transform.rotation.eulerAngles.z;
debug.SetText("Angle: " + turn);
if(turn < -350)
{
turn = turn + 360;
}
BoatRigidBody.MoveRotation(Quaternion.RotateTowards(Boat.transform.rotation, Quaternion.Euler(0, turn, 0), Time.deltaTime * turnDampening));
}
public void AnchorUp()
{
anchorDeployed = false;
Player.transform.parent = Boat.transform;
}
public void AnchorDown()
{
anchorDeployed = true;
Player.transform.parent = null;
}
}