Skip to content

Commit

Permalink
feat: Add Sensitivity to NetworkTransform (#1425)
Browse files Browse the repository at this point in the history
* Add Sensitivity to NetworkTransform

* Removed commented lines

* Made them floats

* Tooltips

* Added comments

* Update NetworkTransformBase.cs

Co-authored-by: vis2k <info@noobtuts.com>
  • Loading branch information
MrGadget and miwarnec committed Jan 16, 2020
1 parent 0a49b43 commit f69f174
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 213 deletions.
16 changes: 13 additions & 3 deletions Assets/Mirror/Components/NetworkTransformBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ public enum Compression { None, Much, Lots, NoRotation }; // easily understandab
// This component could be on the player object or any object that has been assigned authority to this client.
bool isClientWithAuthority => hasAuthority && clientAuthority;

// Sensitivity is added for VR where human players tend to have micro movements so this can quiet down
// the network traffic. Additionally, rigidbody drift should send less traffic, e.g very slow sliding / rolling.
[Header("Sensitivity")]
[Tooltip("Changes to the transform must exceed these values to be transmitted on the network.")]
public float localPositionSensitivity = .01f;
[Tooltip("Changes to the transform must exceed these values to be transmitted on the network.")]
public float localEulerAnglesSensitivity = .01f;
[Tooltip("Changes to the transform must exceed these values to be transmitted on the network.")]
public float localScaleSensitivity = .01f;

// server
Vector3 lastPosition;
Quaternion lastRotation;
Expand Down Expand Up @@ -325,9 +335,9 @@ bool HasEitherMovedRotatedScaled()
{
// moved or rotated or scaled?
// local position/rotation/scale for VR support
bool moved = lastPosition != targetComponent.transform.localPosition;
bool rotated = lastRotation != targetComponent.transform.localRotation;
bool scaled = lastScale != targetComponent.transform.localScale;
bool moved = Vector3.Distance(lastPosition, targetComponent.transform.localPosition) > localPositionSensitivity;
bool rotated = Vector3.Distance(lastRotation.eulerAngles, targetComponent.transform.localRotation.eulerAngles) > localEulerAnglesSensitivity;
bool scaled = Vector3.Distance(lastScale, targetComponent.transform.localScale) > localScaleSensitivity;

// save last for next frame to compare
// (only if change was detected. otherwise slow moving objects might
Expand Down
178 changes: 75 additions & 103 deletions Assets/Mirror/Examples/AdditiveScenes/Prefabs/Player.prefab
Original file line number Diff line number Diff line change
@@ -1,83 +1,5 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &4732749436661138650
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 7418970516927595296}
- component: {fileID: 422209621302968796}
- component: {fileID: 3454051554356895368}
m_Layer: 8
m_Name: Capsule
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &7418970516927595296
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4732749436661138650}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 3254954141432383832}
m_Father: {fileID: 5328458565928408179}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &422209621302968796
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4732749436661138650}
m_Mesh: {fileID: 10208, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &3454051554356895368
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4732749436661138650}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 792117fe9a386a8489e8010bec746339, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!1 &5815001218983416211
GameObject:
m_ObjectHideFlags: 0
Expand All @@ -104,10 +26,10 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5815001218983416211}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0.39999998, z: 0.50499916}
m_LocalPosition: {x: 0, y: 0.39999998, z: 0.505}
m_LocalScale: {x: 0.5, y: 0.099999994, z: 0.19999999}
m_Children: []
m_Father: {fileID: 7418970516927595296}
m_Father: {fileID: 5328458565928408179}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &1800893346221236401
Expand Down Expand Up @@ -164,11 +86,13 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 5328458565928408179}
- component: {fileID: 8537344390966522168}
- component: {fileID: 887491563423388292}
- component: {fileID: 7482234573209362796}
- component: {fileID: 8972496075962964235}
- component: {fileID: 8993127209816276930}
- component: {fileID: 8704659178864205755}
- component: {fileID: 3086414693581178039}
- component: {fileID: 8537344390966522168}
- component: {fileID: 887491563423388292}
m_Layer: 8
m_Name: Player
m_TagString: Untagged
Expand All @@ -187,41 +111,55 @@ Transform:
m_LocalPosition: {x: 0, y: 1.08, z: -20}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 7418970516927595296}
- {fileID: 3254954141432383832}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &8537344390966522168
MonoBehaviour:
--- !u!33 &7482234573209362796
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8872462076811691049}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9b91ecbcc199f4492b9a91e820070131, type: 3}
m_Name:
m_EditorClassIdentifier:
serverOnly: 0
m_AssetId:
m_SceneId: 0
--- !u!114 &887491563423388292
MonoBehaviour:
m_Mesh: {fileID: 10208, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &8972496075962964235
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8872462076811691049}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2f74aedd71d9a4f55b3ce499326d45fb, type: 3}
m_Name:
m_EditorClassIdentifier:
syncMode: 0
syncInterval: 0
compressRotation: 1
clientAuthority: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 792117fe9a386a8489e8010bec746339, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!143 &8993127209816276930
CharacterController:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -282,3 +220,37 @@ MonoBehaviour:
color:
serializedVersion: 2
rgba: 4278190080
--- !u!114 &8537344390966522168
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8872462076811691049}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9b91ecbcc199f4492b9a91e820070131, type: 3}
m_Name:
m_EditorClassIdentifier:
serverOnly: 0
m_AssetId:
m_SceneId: 0
--- !u!114 &887491563423388292
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8872462076811691049}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2f74aedd71d9a4f55b3ce499326d45fb, type: 3}
m_Name:
m_EditorClassIdentifier:
syncMode: 0
syncInterval: 0
compressRotation: 1
clientAuthority: 1
localPositionSensitivity: 0.01
localEulerAnglesSensitivity: 0.01
localScaleSensitivity: 0.01
3 changes: 3 additions & 0 deletions Assets/Mirror/Examples/Pong/Prefabs/Ball.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,6 @@ MonoBehaviour:
syncInterval: 0
compressRotation: 1
clientAuthority: 0
localPositionSensitivity: 0.01
localEulerAnglesSensitivity: 0.01
localScaleSensitivity: 0.01
3 changes: 3 additions & 0 deletions Assets/Mirror/Examples/Pong/Prefabs/Racket.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,6 @@ MonoBehaviour:
syncInterval: 0
compressRotation: 1
clientAuthority: 1
localPositionSensitivity: 0.01
localEulerAnglesSensitivity: 0.01
localScaleSensitivity: 0.01

0 comments on commit f69f174

Please sign in to comment.