mirror of
https://github.com/Kaveinator/NetickProForUnity.git
synced 2025-10-26 09:49:06 -07:00
Fixed an issue with calculating the normal on a box HitShape.
This commit is contained in:
@@ -158,8 +158,8 @@ GameObject:
|
||||
- component: {fileID: 7011933354638177220}
|
||||
- component: {fileID: 5100633453439203130}
|
||||
- component: {fileID: 3197551385548652812}
|
||||
- component: {fileID: 6851739389618402669}
|
||||
- component: {fileID: 1417749684482701243}
|
||||
- component: {fileID: 6918953610149222310}
|
||||
m_Layer: 0
|
||||
m_Name: FPS Player
|
||||
m_TagString: Untagged
|
||||
@@ -223,25 +223,13 @@ MonoBehaviour:
|
||||
TeleportDistance: 50
|
||||
PositionPrecision: 3
|
||||
Settings: 5
|
||||
TransformSpace: 0
|
||||
TransformSpace: 1
|
||||
EnablePredictionErrorCorrectionSmoothing: 0
|
||||
InterpolationMultiplier: 20
|
||||
CorrectionMultiplier: 3
|
||||
CorrectionMaxBlendAlpha: 0.7
|
||||
TeleportErrorThreshold: 50
|
||||
_interpolationSource: 0
|
||||
--- !u!114 &6851739389618402669
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 7011933354638177272}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 754e582306c60a24eb1619b9878f55fd, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
_movementSpeed: 10
|
||||
_sensitivityX: 1.6
|
||||
_sensitivityY: -1
|
||||
_cameraParent: {fileID: 3369032719007731524}
|
||||
<YawPitch>k__BackingField: {x: 0, y: 0}
|
||||
--- !u!143 &1417749684482701243
|
||||
CharacterController:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -268,3 +256,21 @@ CharacterController:
|
||||
m_SkinWidth: 0.08
|
||||
m_MinMoveDistance: 0.001
|
||||
m_Center: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &6918953610149222310
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 7011933354638177272}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 754e582306c60a24eb1619b9878f55fd, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
_renderTransform: {fileID: 4519677825914407182}
|
||||
_movementSpeed: 10
|
||||
_sensitivityX: 1.6
|
||||
_sensitivityY: -1
|
||||
_cameraParent: {fileID: 3369032719007731524}
|
||||
<YawPitch>k__BackingField: {x: 0, y: 0}
|
||||
|
||||
@@ -453,6 +453,11 @@ MonoBehaviour:
|
||||
AutoConnect: 0
|
||||
Port: 36339
|
||||
ServerIPAddress: 127.0.0.1
|
||||
Cap: 1
|
||||
FPS: 450
|
||||
ShowDisconnectButton: 1
|
||||
ShowConnectButton: 1
|
||||
Offset: {x: 36, y: 0}
|
||||
--- !u!4 &1293352709
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -480,6 +485,15 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: d6475ef2cc420914e87d5433265300cf, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
Offset: {x: 27, y: 20}
|
||||
MediumLatencyThreshold: 150
|
||||
HighLatencyThreshold: 250
|
||||
MediumPacketLossThreshold: 1
|
||||
HighPacketLossThreshold: 10
|
||||
PacketLossIconOffset: {x: -80, y: 30}
|
||||
LatencyIconOffset: {x: -80, y: 70}
|
||||
ServerLagIconOffset: {x: -80, y: 110}
|
||||
IconSize: 30
|
||||
--- !u!114 &1293352711
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -790,9 +804,9 @@ Transform:
|
||||
SceneRoots:
|
||||
m_ObjectHideFlags: 0
|
||||
m_Roots:
|
||||
- {fileID: 1293352709}
|
||||
- {fileID: 1318413501}
|
||||
- {fileID: 2022675087}
|
||||
- {fileID: 1318413501}
|
||||
- {fileID: 1293352709}
|
||||
- {fileID: 476934809}
|
||||
- {fileID: 10129275}
|
||||
- {fileID: 1929588644}
|
||||
|
||||
@@ -6,6 +6,9 @@ namespace Netick.Samples.FPS
|
||||
{
|
||||
public class FPSController : NetworkBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private Transform _renderTransform;
|
||||
|
||||
[SerializeField]
|
||||
private float _movementSpeed = 10;
|
||||
[SerializeField]
|
||||
@@ -17,7 +20,7 @@ namespace Netick.Samples.FPS
|
||||
private CharacterController _CC;
|
||||
private Vector2 _camAngles;
|
||||
|
||||
// Networked properties
|
||||
// Networked Properties
|
||||
[Networked][Smooth]
|
||||
public Vector2 YawPitch { get; set; }
|
||||
|
||||
@@ -36,7 +39,7 @@ namespace Netick.Samples.FPS
|
||||
|
||||
public override void OnInputSourceLeft()
|
||||
{
|
||||
// destroy the player object when its input source (controller player) leaves the game
|
||||
// destroy the player object when its input source (controller player) leaves the game.
|
||||
Sandbox.Destroy(Object);
|
||||
}
|
||||
|
||||
@@ -45,15 +48,17 @@ namespace Netick.Samples.FPS
|
||||
if (!IsInputSource || !Sandbox.InputEnabled)
|
||||
return;
|
||||
|
||||
Vector2 input = new Vector2(Input.GetAxisRaw("Mouse X") * _sensitivityX, Input.GetAxisRaw("Mouse Y") * _sensitivityY);
|
||||
Vector2 mouseInputs = new Vector2(Input.GetAxisRaw("Mouse X") * _sensitivityX, Input.GetAxisRaw("Mouse Y") * _sensitivityY);
|
||||
|
||||
var networkInput = Sandbox.GetInput<FPSInput>();
|
||||
networkInput.YawPitch += input;
|
||||
Sandbox.SetInput<FPSInput>(networkInput);
|
||||
var networkInput = Sandbox.GetInput<FPSInput>();
|
||||
networkInput.Movement = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
|
||||
networkInput.ShootInput |= Input.GetMouseButton(0);
|
||||
networkInput.YawPitch += mouseInputs;
|
||||
Sandbox.SetInput(networkInput);
|
||||
|
||||
// we apply the rotation in update too to have smooth camera control
|
||||
_camAngles = ClampAngles(_camAngles.x + input.x, _camAngles.y + input.y);
|
||||
ApplyRotations(_camAngles);
|
||||
// we apply the rotation in update too to have smooth camera control.
|
||||
_camAngles = ClampAngles(_camAngles.x + mouseInputs.x, _camAngles.y + mouseInputs.y);
|
||||
ApplyRotations(_camAngles, false);
|
||||
}
|
||||
|
||||
public override void NetworkFixedUpdate()
|
||||
@@ -64,17 +69,20 @@ namespace Netick.Samples.FPS
|
||||
|
||||
private void MoveAndRotate(FPSInput input)
|
||||
{
|
||||
// rotation
|
||||
YawPitch = ClampAngles(YawPitch.x + input.YawPitch.x, YawPitch.y + input.YawPitch.y);
|
||||
ApplyRotations(YawPitch);
|
||||
// clamp movement inputs.
|
||||
input.Movement = new Vector3(Mathf.Clamp(input.Movement.x, -1f, 1f), Mathf.Clamp(input.Movement.y, -1f, 1f));
|
||||
|
||||
// movement direction
|
||||
var movement = transform.TransformVector(new Vector3(input.Movement.x, 0, input.Movement.y)) * _movementSpeed;
|
||||
movement.y = 0;
|
||||
// rotation.
|
||||
YawPitch = ClampAngles(YawPitch.x + input.YawPitch.x, YawPitch.y + input.YawPitch.y);
|
||||
ApplyRotations(YawPitch,false);
|
||||
|
||||
var gravity = 15f * Vector3.down;
|
||||
// movement direction.
|
||||
var movement = transform.TransformVector(new Vector3(input.Movement.x, 0, input.Movement.y)) * _movementSpeed;
|
||||
movement.y = 0;
|
||||
|
||||
// move
|
||||
var gravity = 15f * Vector3.down;
|
||||
|
||||
// move.
|
||||
_CC.Move((movement + gravity) * Sandbox.FixedDeltaTime);
|
||||
}
|
||||
|
||||
@@ -82,26 +90,28 @@ namespace Netick.Samples.FPS
|
||||
[OnChanged(nameof(YawPitch), invokeDuringResimulation: true)]
|
||||
private void OnYawPitchChanged(OnChangedData onChanged)
|
||||
{
|
||||
ApplyRotations(YawPitch);
|
||||
ApplyRotations(YawPitch, false);
|
||||
}
|
||||
|
||||
public override void NetworkRender()
|
||||
{
|
||||
if (IsProxy)
|
||||
ApplyRotations(YawPitch);
|
||||
ApplyRotations(YawPitch, true);
|
||||
}
|
||||
|
||||
private void ApplyRotations(Vector2 camAngles)
|
||||
private void ApplyRotations(Vector2 camAngles, bool isProxy)
|
||||
{
|
||||
// on the player transform, we apply yaw
|
||||
transform.rotation = Quaternion.Euler(new Vector3(0, camAngles.x, 0));
|
||||
// on the player transform, we apply yaw.
|
||||
if (isProxy)
|
||||
_renderTransform.rotation = Quaternion.Euler(new Vector3(0, camAngles.x, 0));
|
||||
else
|
||||
transform.rotation = Quaternion.Euler(new Vector3(0, camAngles.x, 0));
|
||||
|
||||
// on the weapon/camera holder, we apply the pitch angle
|
||||
// on the weapon/camera holder, we apply the pitch angle.
|
||||
_cameraParent.localEulerAngles = new Vector3(camAngles.y, 0, 0);
|
||||
_camAngles = camAngles;
|
||||
}
|
||||
|
||||
|
||||
private Vector2 ClampAngles(float yaw, float pitch)
|
||||
{
|
||||
return new Vector2(ClampAngle(yaw, -360, 360), ClampAngle(pitch, -80, 80));
|
||||
|
||||
@@ -9,16 +9,6 @@ namespace Netick.Samples.FPS
|
||||
public Transform SpawnPos;
|
||||
public GameObject PlayerPrefab;
|
||||
|
||||
// This is called to read inputs.
|
||||
public override void OnInput(NetworkSandbox sandbox)
|
||||
{
|
||||
var input = sandbox.GetInput<FPSInput>();
|
||||
|
||||
input.Movement = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
|
||||
input.ShootInput |= Input.GetMouseButton(0);
|
||||
sandbox.SetInput<FPSInput>(input);
|
||||
}
|
||||
|
||||
// This is called on the server when a player has connected.
|
||||
public override void OnPlayerConnected(NetworkSandbox sandbox, NetworkPlayer networkPlayer)
|
||||
{
|
||||
|
||||
@@ -3,10 +3,13 @@ using Netick;
|
||||
|
||||
namespace Netick.Samples.FPS
|
||||
{
|
||||
[Networked]
|
||||
public struct FPSInput : INetworkInput
|
||||
{
|
||||
public Vector2 YawPitch;
|
||||
public Vector2 Movement;
|
||||
[Networked]
|
||||
public Vector2 YawPitch { get; set; }
|
||||
[Networked]
|
||||
public Vector2 Movement { get; set; }
|
||||
public NetworkBool ShootInput;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user