-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerMountControl.cs
More file actions
43 lines (38 loc) · 1.41 KB
/
PlayerMountControl.cs
File metadata and controls
43 lines (38 loc) · 1.41 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
// put all mount control code into a separate component.
// => for consistency with PetControl
// => if we need mount inventories, then we can put the Cmds in here too later
using UnityEngine;
using Mirror;
namespace uMMORPG
{
[DisallowMultipleComponent]
public class PlayerMountControl : NetworkBehaviour
{
[Header("Mount")]
public Transform meshToOffsetWhenMounted;
public float seatOffsetY = -1;
// 'Mount' can't be SyncVar so we use [SyncVar] GameObject and wrap it
[SyncVar, HideInInspector] public Mount activeMount;
void LateUpdate()
{
// follow mount's seat position if mounted
// (on server too, for correct collider position and calculations)
ApplyMountSeatOffset();
}
public bool IsMounted()
{
return activeMount != null && activeMount.health.current > 0;
}
void ApplyMountSeatOffset()
{
if (meshToOffsetWhenMounted != null)
{
// apply seat offset if on mount (not a dead one), reset otherwise
if (activeMount != null && activeMount.health.current > 0)
meshToOffsetWhenMounted.transform.position = activeMount.seat.position + Vector3.up * seatOffsetY;
else
meshToOffsetWhenMounted.transform.localPosition = Vector3.zero;
}
}
}
}