-
Notifications
You must be signed in to change notification settings - Fork 0
/
CodingThings.txt
151 lines (91 loc) · 3.42 KB
/
CodingThings.txt
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
you could do
Vector3 vec = new Vector3
{
x = ...
y = ...
z = ...
};
transform.position = targetToFollow.position + new Vector3(xOffset, yOffset, zOffset);
transform.position = new Vector3
{
x = targetToFollow.position.x + xOffset,
y = targetToFollow.position.y + yOffset,
z = targetToFollow.position.z + zOffset
};
transform.rotation = new Quaternion
{
x = Mathf.Deg2Rad * xRotation,
y = Mathf.Deg2Rad * yRotation,
z = Mathf.Deg2Rad * zRotation,
w = Quaternion.identity.w
};
transform.rotation = Quaternion.Euler(x, y, z);
ok looks like NetworkManager does its stuff in Start
so you can make another component that will change the port in Awake and it should run fine
also, try replacing this
transform.Translate(desiredMoveDirection * MoveSpeed * Time.deltaTime);
with Rigidbody.MovePosition
to rotate, you do X and Y rotation of the pivot object
This just might be
and for zoom you change the Z pos of the MainCamera
DecayingDevToday at 10:15 PM
what exactly is that camera pivot object?
MediocreToday at 10:16 PM
just an empty GO
but you would sync its position to the player
think like a selfie stick
use this to get mouse input
float mouseX = Input.GetAxis("Mouse X");
float mouseY = Input.GetAxis("Mouse Y");
you probably also want to clamp the x rotation
Vector3 euler = cameraPivot.localEulerAngles;
euler.x = Mathf.Clamp(Mathf.Repeat(cameraPivot.eulerAngles.x + 180, 360), minY, maxY) - 180;
cameraPivot.localEulerAngles = euler;
but i prefer separate, then do a smooth follow using Vector3.SmoothDamp
this will hopefully also cause less motion sickness if your player does some sick moves like backflips xD
there will be 2 options
1 local splitscreenmultiplayer(1 player, 2, 3 4? 43?)
2 LAN multiplayer with only one screen per player
----------------------------------------------------------------------------
private SimpleControls controls;
private Vector2 m_Move;
private Vector2 m_Look;
private Vector2 m_Rotation;
public void Awake()
{
controls = new SimpleControls();
controls.gameplay.move.performed += ctx => m_Move = ctx.ReadValue<Vector2>();
controls.gameplay.look.performed += ctx => m_Look = ctx.ReadValue<Vector2>();
controls.gameplay.move.canceled += ctx => m_Move = Vector2.zero;
controls.gameplay.look.canceled += ctx => m_Look = Vector2.zero;
public void OnEnable()
{
controls.Enable();
}
public void OnDisable()
{
controls.Disable();
}
public void Update()
{
Move(m_Move);
Look(m_Look);
}
private void Move(Vector2 direction)
{
var scaledMoveSpeed = moveSpeed * Time.deltaTime;
var move = transform.TransformDirection(direction.x, 0, direction.y);
transform.localPosition += move * scaledMoveSpeed;
}
private void Look(Vector2 rotate)
{
const float kClampAngle = 80.0f;
m_Rotation.y += rotate.x * rotateSpeed * Time.deltaTime;
m_Rotation.x -= rotate.y * rotateSpeed * Time.deltaTime;
m_Rotation.x = Mathf.Clamp(m_Rotation.x, -kClampAngle, kClampAngle);
var localRotation = Quaternion.Euler(m_Rotation.x, m_Rotation.y, 0.0f);
transform.rotation = localRotation;
}
[Server]
if(isServer)
NetworkServer.connections is a dictionary of all clients (players)