feat: Distributed Authority Sample player locomotion [MTT-8898] (#200)

* initial project commit

* Added: proposed folder structure from TDD

* consolidating settings folders

* adding ignored temp script for testing connection

* importing asteroids base classes & locomotion controller wip

* reworked drag, inheriting from baseobject movement

* cleanup, avatar set with AvatarTransform

* distinguishing spawmed players with name in hierarchy

* moving AvatarTransformEditor to own Editor subdirectory class, cleanup

* formatting changes

---------

Co-authored-by: Elfi Kühndorf <elfi.kuhndorf@unity3d.com>
This commit is contained in:
Fernando Cortez 2024-08-08 11:44:14 -04:00 коммит произвёл GitHub
Родитель d2ce416ccd
Коммит a4b1009a2d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
15 изменённых файлов: 1927 добавлений и 149 удалений

Просмотреть файл

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4712f1f593c284efd924c2fd58555653
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,14 @@
fileFormatVersion: 2
guid: dcd1b4eb76b964f40afe6c0a3ca65c82
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 8404be70184654265930450def6a9037, type: 3}
generateWrapperCode: 0
wrapperCodePath:
wrapperClassName:
wrapperCodeNamespace:

Просмотреть файл

@ -1,5 +1,91 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &2971605785670457434
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 370971123281630519}
- component: {fileID: 3081239909905841813}
- component: {fileID: 5988919140179887555}
m_Layer: 0
m_Name: Cube
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &370971123281630519
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2971605785670457434}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0.5, z: 0.5}
m_LocalScale: {x: 0.5, y: 0.2, z: 0.54218}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 527982249900556139}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &3081239909905841813
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2971605785670457434}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &5988919140179887555
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2971605785670457434}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RayTracingAccelStructBuildFlagsOverride: 0
m_RayTracingAccelStructBuildFlags: 1
m_SmallMeshCulling: 1
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 31321ba15b8f8eb4c954353edc038b1d, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
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
m_AdditionalVertexStreams: {fileID: 0}
--- !u!1 &3998769334658168242
GameObject:
m_ObjectHideFlags: 0
@ -31,7 +117,8 @@ Transform:
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Children:
- {fileID: 370971123281630519}
m_Father: {fileID: 378099091213283077}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &5867719757342769277
@ -120,6 +207,11 @@ GameObject:
m_Component:
- component: {fileID: 378099091213283077}
- component: {fileID: 2864305741433477372}
- component: {fileID: 5446307037829169848}
- component: {fileID: 4745766379562620470}
- component: {fileID: -8100831418301897270}
- component: {fileID: 4903152183366241606}
- component: {fileID: 8197190117666738524}
m_Layer: 0
m_Name: Avatar
m_TagString: Untagged
@ -166,3 +258,139 @@ MonoBehaviour:
SpawnWithObservers: 1
DontDestroyWithOwner: 0
AutoObjectParentSync: 1
--- !u!114 &5446307037829169848
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5478015027486214707}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5e253f865ab604b12a7f84e3d97704d8, type: 3}
m_Name:
m_EditorClassIdentifier:
AuthorityMode: 1
UseUnreliableDeltas: 0
SyncPositionX: 1
SyncPositionY: 1
SyncPositionZ: 1
SyncRotAngleX: 0
SyncRotAngleY: 1
SyncRotAngleZ: 0
SyncScaleX: 0
SyncScaleY: 0
SyncScaleZ: 0
PositionThreshold: 0.001
RotAngleThreshold: 0.01
ScaleThreshold: 0.01
UseQuaternionSynchronization: 0
UseQuaternionCompression: 0
UseHalfFloatPrecision: 0
InLocalSpace: 0
Interpolate: 1
SlerpPosition: 0
PropertiesVisible: 1
m_Rigidbody: {fileID: 4745766379562620470}
m_PlayerInput: {fileID: 4903152183366241606}
m_AvatarInputs: {fileID: 8197190117666738524}
m_WalkSpeed: 6
m_SprintSpeed: 10
m_Acceleration: 50
m_DragCoefficient: 4
m_AirControlFactor: 0.5
m_JumpImpusle: 7
m_CustomGravityMultiplier: 2
m_RotationSpeed: 700
m_GroundCheckDistance: 1.1
--- !u!54 &4745766379562620470
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5478015027486214707}
serializedVersion: 4
m_Mass: 1
m_Drag: 0
m_AngularDrag: 0.05
m_CenterOfMass: {x: 0, y: 0, z: 0}
m_InertiaTensor: {x: 1, y: 1, z: 1}
m_InertiaRotation: {x: 0, y: 0, z: 0, w: 1}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_ImplicitCom: 1
m_ImplicitTensor: 1
m_UseGravity: 1
m_IsKinematic: 1
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!114 &-8100831418301897270
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5478015027486214707}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f6c0be61502bb534f922ebb746851216, type: 3}
m_Name:
m_EditorClassIdentifier:
UseRigidBodyForMotion: 1
AutoUpdateKinematicState: 1
AutoSetKinematicOnDespawn: 1
--- !u!114 &4903152183366241606
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5478015027486214707}
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 62899f850307741f2a39c98a8b639597, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Actions: {fileID: -944628639613478452, guid: dcd1b4eb76b964f40afe6c0a3ca65c82, type: 3}
m_NotificationBehavior: 0
m_UIInputModule: {fileID: 0}
m_DeviceLostEvent:
m_PersistentCalls:
m_Calls: []
m_DeviceRegainedEvent:
m_PersistentCalls:
m_Calls: []
m_ControlsChangedEvent:
m_PersistentCalls:
m_Calls: []
m_ActionEvents: []
m_NeverAutoSwitchControlSchemes: 0
m_DefaultControlScheme:
m_DefaultActionMap: Player
m_SplitScreenIndex: -1
m_Camera: {fileID: 0}
--- !u!114 &8197190117666738524
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5478015027486214707}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7e9f71718dd134b14b300e378e98c718, type: 3}
m_Name:
m_EditorClassIdentifier:
move: {x: 0, y: 0}
look: {x: 0, y: 0}
jump: 0
sprint: 0
analogMovement: 0
cursorLocked: 1
cursorInputForLook: 1

Просмотреть файл

@ -288,6 +288,159 @@ Transform:
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1305680749
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1305680751}
- component: {fileID: 1305680750}
m_Layer: 0
m_Name: RigidbodyContactEventManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1305680750
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1305680749}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 739e5cee846b6384988f9a47e4691836, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!4 &1305680751
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1305680749}
serializedVersion: 2
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_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1888825843
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1888825847}
- component: {fileID: 1888825846}
- component: {fileID: 1888825845}
- component: {fileID: 1888825844}
m_Layer: 0
m_Name: Plane
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!64 &1888825844
MeshCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1888825843}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 0
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 5
m_Convex: 0
m_CookingOptions: 30
m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &1888825845
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1888825843}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RayTracingAccelStructBuildFlagsOverride: 0
m_RayTracingAccelStructBuildFlags: 1
m_SmallMeshCulling: 1
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 31321ba15b8f8eb4c954353edc038b1d, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
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
m_AdditionalVertexStreams: {fileID: 0}
--- !u!33 &1888825846
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1888825843}
m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &1888825847
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1888825843}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 100, y: 1, z: 100}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &2024073102
PrefabInstance:
m_ObjectHideFlags: 0
@ -352,3 +505,5 @@ SceneRoots:
- {fileID: 410087041}
- {fileID: 832575519}
- {fileID: 2024073102}
- {fileID: 1888825847}
- {fileID: 1305680751}

Просмотреть файл

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 76f900e572a03416bbb376adc24c438e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -0,0 +1,32 @@
using com.unity.multiplayer.samples.distributed_authority.gameplay;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
namespace com.unity.multiplayer.samples.distributed_authority.editor
{
[CustomEditor(typeof(AvatarTransform))]
class DerivedComponentEditor : Editor
{
public override VisualElement CreateInspectorGUI()
{
// Create a new VisualElement to be the root of the inspector UI
var root = new VisualElement();
// Generate default inspector for AvatarTransform
serializedObject.Update();
SerializedProperty property = serializedObject.GetIterator();
property.NextVisible(true); // Skip the script field
while (property.NextVisible(false))
{
var propertyField = new PropertyField(property);
root.Add(propertyField);
}
serializedObject.ApplyModifiedProperties();
return root;
}
}
}

Просмотреть файл

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 2ad6787b48af94939adc8213c08bd3eb

Просмотреть файл

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: db21498511bd04a938d047c45c5de887
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -0,0 +1,83 @@
using UnityEngine;
using UnityEngine.InputSystem;
namespace com.unity.multiplayer.samples.distributed_authority.input
{
class AvatarInputs : MonoBehaviour
{
[Header("Character Input Values")]
[SerializeField]
internal Vector2 Move;
[SerializeField]
internal Vector2 Look;
[SerializeField]
internal bool Jump;
[SerializeField]
internal bool Sprint;
[Header("Movement Settings")]
[SerializeField]
internal bool AnalogMovement;
[Header("Mouse Cursor Settings")]
[SerializeField]
internal bool CursorLocked = true;
[SerializeField]
internal bool CursorInputForLook = true;
#if ENABLE_INPUT_SYSTEM
void OnMove(InputValue value)
{
MoveInput(value.Get<Vector2>());
}
void OnLook(InputValue value)
{
if (CursorInputForLook)
{
LookInput(value.Get<Vector2>());
}
}
void OnJump(InputValue value)
{
JumpInput(value.isPressed);
}
void OnSprint(InputValue value)
{
SprintInput(value.isPressed);
}
#endif
void MoveInput(Vector2 newMoveDirection)
{
Move = newMoveDirection;
}
void LookInput(Vector2 newLookDirection)
{
Look = newLookDirection;
}
void JumpInput(bool newJumpState)
{
Jump = newJumpState;
}
void SprintInput(bool newSprintState)
{
Sprint = newSprintState;
}
void OnApplicationFocus(bool hasFocus)
{
SetCursorState(CursorLocked);
}
void SetCursorState(bool newState)
{
Cursor.lockState = newState ? CursorLockMode.Locked : CursorLockMode.None;
}
}
}

Просмотреть файл

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 7e9f71718dd134b14b300e378e98c718

Просмотреть файл

@ -0,0 +1,179 @@
using Unity.Netcode.Components;
using UnityEngine;
using UnityEngine.InputSystem;
using com.unity.multiplayer.samples.distributed_authority.input;
namespace com.unity.multiplayer.samples.distributed_authority.gameplay
{
[RequireComponent(typeof(Rigidbody))]
public class AvatarTransform : NetworkTransform
{
[SerializeField]
Rigidbody m_Rigidbody;
[SerializeField]
PlayerInput m_PlayerInput;
[SerializeField]
AvatarInputs m_AvatarInputs;
[SerializeField]
float m_WalkSpeed;
[SerializeField]
float m_SprintSpeed;
[SerializeField]
float m_Acceleration;
[SerializeField]
float m_DragCoefficient;
[SerializeField]
float m_AirControlFactor;
[SerializeField]
float m_JumpImpusle;
[SerializeField]
float m_CustomGravityMultiplier;
[SerializeField]
float m_RotationSpeed;
[SerializeField]
float m_GroundCheckDistance;
Vector3 m_Movement;
// grab jump state from input and clear after consumed
bool m_Jump;
// cached grounded check
bool m_IsGrounded;
RaycastHit[] m_RaycastHits = new RaycastHit[1];
Ray m_Ray;
public override void OnNetworkSpawn()
{
base.OnNetworkSpawn();
gameObject.name = $"[Client-{OwnerClientId}]{name}";
if (!HasAuthority)
{
return;
}
m_PlayerInput.enabled = true;
m_Rigidbody.isKinematic = false;
// Freeze rotation on the x and z axes to prevent toppling
m_Rigidbody.freezeRotation = true;
var spawnPosition = new Vector3(0f, 1.5f, 0f);
transform.SetPositionAndRotation(position: spawnPosition, rotation: Quaternion.identity);
m_Rigidbody.position = spawnPosition;
m_Rigidbody.linearVelocity = Vector3.zero;
}
void Update()
{
if (!IsSpawned || !HasAuthority)
{
return;
}
m_Movement = new Vector3(m_AvatarInputs.Move.x, 0, m_AvatarInputs.Move.y).normalized;
// Handle rotation based on input direction
if (m_Movement.magnitude >= 0.1f)
{
var targetAngle = Mathf.Atan2(m_Movement.x, m_Movement.z) * Mathf.Rad2Deg;
var targetRotation = Quaternion.Euler(0, targetAngle, 0);
transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, Time.deltaTime * m_RotationSpeed);
}
if (IsGrounded() && m_AvatarInputs.Jump)
{
m_Jump = true;
m_AvatarInputs.Jump = false;
}
}
void ApplyMovement()
{
if (Mathf.Approximately(m_Movement.magnitude, 0f))
{
return;
}
var velocity = m_Rigidbody.linearVelocity;
var desiredVelocity = m_Movement * (m_AvatarInputs.Sprint ? m_SprintSpeed : m_WalkSpeed);
var targetVelocity = new Vector3(desiredVelocity.x, velocity.y, desiredVelocity.z);
var velocityChange = targetVelocity - velocity;
if (m_IsGrounded)
{
// Apply force proportional to acceleration while grounded
var force = velocityChange * m_Acceleration;
m_Rigidbody.AddForce(force, ForceMode.Acceleration);
}
else
{
// Apply reduced force in the air for air control
var force = velocityChange * (m_Acceleration * m_AirControlFactor);
m_Rigidbody.AddForce(force, ForceMode.Acceleration);
}
}
void ApplyJump()
{
if (m_IsGrounded && m_Jump)
{
m_Rigidbody.AddForce(Vector3.up * m_JumpImpusle, ForceMode.Impulse);
m_Jump = false;
}
}
void UpdateGroundedStatus()
{
m_IsGrounded = IsGrounded();
}
bool IsGrounded()
{
// Perform a raycast to check if the character is grounded
m_Ray.origin = m_Rigidbody.worldCenterOfMass;
m_Ray.direction = Vector3.down;
return Physics.RaycastNonAlloc(m_Ray, m_RaycastHits, m_GroundCheckDistance) > 0;
}
void FixedUpdate()
{
if (!IsSpawned || !HasAuthority || m_Rigidbody != null && m_Rigidbody.isKinematic)
{
return;
}
UpdateGroundedStatus();
ApplyMovement();
ApplyJump();
ApplyDrag();
ApplyCustomGravity();
}
void ApplyDrag()
{
var groundVelocity = m_Rigidbody.linearVelocity;
groundVelocity.y = 0f;
if (groundVelocity.magnitude > 0f)
{
// Apply deceleration force to stop movement
var dragForce = -m_DragCoefficient * groundVelocity.magnitude * groundVelocity;
m_Rigidbody.AddForce(dragForce, ForceMode.Acceleration);
}
}
void ApplyCustomGravity()
{
// custom gravity
if (!m_IsGrounded)
{
var customGravity = Physics.gravity * (m_CustomGravityMultiplier - 1);
m_Rigidbody.AddForce(customGravity, ForceMode.Acceleration);
}
}
}
}

Просмотреть файл

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 5e253f865ab604b12a7f84e3d97704d8

Просмотреть файл

@ -16,5 +16,5 @@ EditorBuildSettings:
guid: 99c9720ab356a0642a771bea13969a05
m_configObjects:
com.unity.input.settings: {fileID: 11400000, guid: 9e7be553448fa2546aea5752021cbcf7, type: 2}
com.unity.input.settings.actions: {fileID: -944628639613478452, guid: 7b30a29548072524e9f8362bcbe40502, type: 3}
com.unity.input.settings.actions: {fileID: -944628639613478452, guid: dcd1b4eb76b964f40afe6c0a3ca65c82, type: 3}
m_UseUCBPForAssetBundles: 0

Просмотреть файл

@ -176,7 +176,7 @@ PlayerSettings:
AndroidMinSdkVersion: 23
AndroidTargetSdkVersion: 0
AndroidPreferredInstallLocation: 1
aotOptions:
aotOptions:
stripEngineCode: 1
iPhoneStrippingLevel: 0
iPhoneScriptCallOptimization: 0
@ -228,8 +228,8 @@ PlayerSettings:
rgba: 0
iOSLaunchScreeniPadFillPct: 100
iOSLaunchScreeniPadSize: 100
iOSLaunchScreenCustomStoryboardPath:
iOSLaunchScreeniPadCustomStoryboardPath:
iOSLaunchScreenCustomStoryboardPath:
iOSLaunchScreeniPadCustomStoryboardPath:
iOSDeviceRequirements: []
iOSURLSchemes: []
macOSURLSchemes: []
@ -240,10 +240,10 @@ PlayerSettings:
metalCompileShaderBinary: 0
iOSRenderExtraFrameOnPause: 0
iosCopyPluginsCodeInsteadOfSymlink: 0
appleDeveloperTeamID:
iOSManualSigningProvisioningProfileID:
tvOSManualSigningProvisioningProfileID:
VisionOSManualSigningProvisioningProfileID:
appleDeveloperTeamID:
iOSManualSigningProvisioningProfileID:
tvOSManualSigningProvisioningProfileID:
VisionOSManualSigningProvisioningProfileID:
iOSManualSigningProvisioningProfileType: 0
tvOSManualSigningProvisioningProfileType: 0
VisionOSManualSigningProvisioningProfileType: 0
@ -266,8 +266,8 @@ PlayerSettings:
AndroidTargetArchitectures: 2
AndroidSplashScreenScale: 0
androidSplashScreen: {fileID: 0}
AndroidKeystoreName:
AndroidKeyaliasName:
AndroidKeystoreName:
AndroidKeyaliasName:
AndroidEnableArmv9SecurityFeatures: 0
AndroidEnableArm64MTE: 0
AndroidBuildApkPerCpuArchitecture: 0
@ -393,129 +393,129 @@ PlayerSettings:
m_Width: 432
m_Height: 432
m_Kind: 2
m_SubKind:
m_SubKind:
- m_Textures: []
m_Width: 324
m_Height: 324
m_Kind: 2
m_SubKind:
m_SubKind:
- m_Textures: []
m_Width: 216
m_Height: 216
m_Kind: 2
m_SubKind:
m_SubKind:
- m_Textures: []
m_Width: 162
m_Height: 162
m_Kind: 2
m_SubKind:
m_SubKind:
- m_Textures: []
m_Width: 108
m_Height: 108
m_Kind: 2
m_SubKind:
m_SubKind:
- m_Textures: []
m_Width: 81
m_Height: 81
m_Kind: 2
m_SubKind:
m_SubKind:
- m_Textures: []
m_Width: 192
m_Height: 192
m_Kind: 1
m_SubKind:
m_SubKind:
- m_Textures: []
m_Width: 144
m_Height: 144
m_Kind: 1
m_SubKind:
m_SubKind:
- m_Textures: []
m_Width: 96
m_Height: 96
m_Kind: 1
m_SubKind:
m_SubKind:
- m_Textures: []
m_Width: 72
m_Height: 72
m_Kind: 1
m_SubKind:
m_SubKind:
- m_Textures: []
m_Width: 48
m_Height: 48
m_Kind: 1
m_SubKind:
m_SubKind:
- m_Textures: []
m_Width: 36
m_Height: 36
m_Kind: 1
m_SubKind:
m_SubKind:
- m_Textures: []
m_Width: 192
m_Height: 192
m_Kind: 0
m_SubKind:
m_SubKind:
- m_Textures: []
m_Width: 144
m_Height: 144
m_Kind: 0
m_SubKind:
m_SubKind:
- m_Textures: []
m_Width: 96
m_Height: 96
m_Kind: 0
m_SubKind:
m_SubKind:
- m_Textures: []
m_Width: 72
m_Height: 72
m_Kind: 0
m_SubKind:
m_SubKind:
- m_Textures: []
m_Width: 48
m_Height: 48
m_Kind: 0
m_SubKind:
m_SubKind:
- m_Textures: []
m_Width: 36
m_Height: 36
m_Kind: 0
m_SubKind:
m_SubKind:
- m_BuildTarget: tvOS
m_Icons:
- m_Textures: []
m_Width: 1280
m_Height: 768
m_Kind: 0
m_SubKind:
m_SubKind:
- m_Textures: []
m_Width: 800
m_Height: 480
m_Kind: 0
m_SubKind:
m_SubKind:
- m_Textures: []
m_Width: 400
m_Height: 240
m_Kind: 0
m_SubKind:
m_SubKind:
- m_Textures: []
m_Width: 4640
m_Height: 1440
m_Kind: 1
m_SubKind:
m_SubKind:
- m_Textures: []
m_Width: 2320
m_Height: 720
m_Kind: 1
m_SubKind:
m_SubKind:
- m_Textures: []
m_Width: 3840
m_Height: 1440
m_Kind: 1
m_SubKind:
m_SubKind:
- m_Textures: []
m_Width: 1920
m_Height: 720
m_Kind: 1
m_SubKind:
m_SubKind:
m_BuildTargetBatching: []
m_BuildTargetShaderSettings: []
m_BuildTargetGraphicsJobs: []
@ -557,13 +557,13 @@ PlayerSettings:
enableInternalProfiler: 0
logObjCUncaughtExceptions: 1
enableCrashReportAPI: 0
cameraUsageDescription:
locationUsageDescription:
microphoneUsageDescription:
bluetoothUsageDescription:
cameraUsageDescription:
locationUsageDescription:
microphoneUsageDescription:
bluetoothUsageDescription:
macOSTargetOSVersion: 11.0
switchNMETAOverride:
switchNetLibKey:
switchNMETAOverride:
switchNetLibKey:
switchSocketMemoryPoolSize: 6144
switchSocketAllocatorPoolSize: 128
switchSocketConcurrencyLimit: 14
@ -572,40 +572,40 @@ PlayerSettings:
switchEnableFileSystemTrace: 0
switchLTOSetting: 0
switchApplicationID: 0x01004b9000490000
switchNSODependencies:
switchCompilerFlags:
switchTitleNames_0:
switchTitleNames_1:
switchTitleNames_2:
switchTitleNames_3:
switchTitleNames_4:
switchTitleNames_5:
switchTitleNames_6:
switchTitleNames_7:
switchTitleNames_8:
switchTitleNames_9:
switchTitleNames_10:
switchTitleNames_11:
switchTitleNames_12:
switchTitleNames_13:
switchTitleNames_14:
switchTitleNames_15:
switchPublisherNames_0:
switchPublisherNames_1:
switchPublisherNames_2:
switchPublisherNames_3:
switchPublisherNames_4:
switchPublisherNames_5:
switchPublisherNames_6:
switchPublisherNames_7:
switchPublisherNames_8:
switchPublisherNames_9:
switchPublisherNames_10:
switchPublisherNames_11:
switchPublisherNames_12:
switchPublisherNames_13:
switchPublisherNames_14:
switchPublisherNames_15:
switchNSODependencies:
switchCompilerFlags:
switchTitleNames_0:
switchTitleNames_1:
switchTitleNames_2:
switchTitleNames_3:
switchTitleNames_4:
switchTitleNames_5:
switchTitleNames_6:
switchTitleNames_7:
switchTitleNames_8:
switchTitleNames_9:
switchTitleNames_10:
switchTitleNames_11:
switchTitleNames_12:
switchTitleNames_13:
switchTitleNames_14:
switchTitleNames_15:
switchPublisherNames_0:
switchPublisherNames_1:
switchPublisherNames_2:
switchPublisherNames_3:
switchPublisherNames_4:
switchPublisherNames_5:
switchPublisherNames_6:
switchPublisherNames_7:
switchPublisherNames_8:
switchPublisherNames_9:
switchPublisherNames_10:
switchPublisherNames_11:
switchPublisherNames_12:
switchPublisherNames_13:
switchPublisherNames_14:
switchPublisherNames_15:
switchIcons_0: {fileID: 0}
switchIcons_1: {fileID: 0}
switchIcons_2: {fileID: 0}
@ -638,18 +638,18 @@ PlayerSettings:
switchSmallIcons_13: {fileID: 0}
switchSmallIcons_14: {fileID: 0}
switchSmallIcons_15: {fileID: 0}
switchManualHTML:
switchAccessibleURLs:
switchLegalInformation:
switchManualHTML:
switchAccessibleURLs:
switchLegalInformation:
switchMainThreadStackSize: 1048576
switchPresenceGroupId:
switchPresenceGroupId:
switchLogoHandling: 0
switchReleaseVersion: 0
switchDisplayVersion: 1.0.0
switchStartupUserAccount: 0
switchSupportedLanguagesMask: 0
switchLogoType: 0
switchApplicationErrorCodeCategory:
switchApplicationErrorCodeCategory:
switchUserAccountSaveDataSize: 0
switchUserAccountSaveDataJournalSize: 0
switchApplicationAttribute: 0
@ -669,14 +669,14 @@ PlayerSettings:
switchRatingsInt_10: 0
switchRatingsInt_11: 0
switchRatingsInt_12: 0
switchLocalCommunicationIds_0:
switchLocalCommunicationIds_1:
switchLocalCommunicationIds_2:
switchLocalCommunicationIds_3:
switchLocalCommunicationIds_4:
switchLocalCommunicationIds_5:
switchLocalCommunicationIds_6:
switchLocalCommunicationIds_7:
switchLocalCommunicationIds_0:
switchLocalCommunicationIds_1:
switchLocalCommunicationIds_2:
switchLocalCommunicationIds_3:
switchLocalCommunicationIds_4:
switchLocalCommunicationIds_5:
switchLocalCommunicationIds_6:
switchLocalCommunicationIds_7:
switchParentalControl: 0
switchAllowsScreenshot: 1
switchAllowsVideoCapturing: 1
@ -708,35 +708,35 @@ PlayerSettings:
switchRamDiskSpaceSize: 12
switchUpgradedPlayerSettingsToNMETA: 0
ps4NPAgeRating: 12
ps4NPTitleSecret:
ps4NPTrophyPackPath:
ps4NPTitleSecret:
ps4NPTrophyPackPath:
ps4ParentalLevel: 11
ps4ContentID: ED1633-NPXX51362_00-0000000000000000
ps4Category: 0
ps4MasterVersion: 01.00
ps4AppVersion: 01.00
ps4AppType: 0
ps4ParamSfxPath:
ps4ParamSfxPath:
ps4VideoOutPixelFormat: 0
ps4VideoOutInitialWidth: 1920
ps4VideoOutBaseModeInitialWidth: 1920
ps4VideoOutReprojectionRate: 60
ps4PronunciationXMLPath:
ps4PronunciationSIGPath:
ps4BackgroundImagePath:
ps4StartupImagePath:
ps4StartupImagesFolder:
ps4IconImagesFolder:
ps4SaveDataImagePath:
ps4SdkOverride:
ps4BGMPath:
ps4ShareFilePath:
ps4ShareOverlayImagePath:
ps4PrivacyGuardImagePath:
ps4ExtraSceSysFile:
ps4NPtitleDatPath:
ps4PronunciationXMLPath:
ps4PronunciationSIGPath:
ps4BackgroundImagePath:
ps4StartupImagePath:
ps4StartupImagesFolder:
ps4IconImagesFolder:
ps4SaveDataImagePath:
ps4SdkOverride:
ps4BGMPath:
ps4ShareFilePath:
ps4ShareOverlayImagePath:
ps4PrivacyGuardImagePath:
ps4ExtraSceSysFile:
ps4NPtitleDatPath:
ps4RemotePlayKeyAssignment: -1
ps4RemotePlayKeyMappingDir:
ps4RemotePlayKeyMappingDir:
ps4PlayTogetherPlayerCount: 0
ps4EnterButtonAssignment: 2
ps4ApplicationParam1: 0
@ -764,9 +764,9 @@ PlayerSettings:
ps4ScriptOptimizationLevel: 2
ps4Audio3dVirtualSpeakerCount: 14
ps4attribCpuUsage: 0
ps4PatchPkgPath:
ps4PatchLatestPkgPath:
ps4PatchChangeinfoPath:
ps4PatchPkgPath:
ps4PatchLatestPkgPath:
ps4PatchChangeinfoPath:
ps4PatchDayOne: 0
ps4attribUserManagement: 0
ps4attribMoveSupport: 0
@ -782,19 +782,19 @@ PlayerSettings:
ps4attribEyeToEyeDistanceSettingVR: 0
ps4IncludedModules: []
ps4attribVROutputEnabled: 0
monoEnv:
monoEnv:
splashScreenBackgroundSourceLandscape: {fileID: 0}
splashScreenBackgroundSourcePortrait: {fileID: 0}
blurSplashScreenBackground: 1
spritePackerPolicy:
spritePackerPolicy:
webGLMemorySize: 32
webGLExceptionSupport: 1
webGLNameFilesAsHashes: 0
webGLShowDiagnostics: 0
webGLDataCaching: 1
webGLDebugSymbols: 0
webGLEmscriptenArgs:
webGLModulesDirectory:
webGLEmscriptenArgs:
webGLModulesDirectory:
webGLTemplate: APPLICATION:Default
webGLAnalyzeBuildSize: 0
webGLUseEmbeddedResources: 0
@ -816,7 +816,7 @@ PlayerSettings:
webGLCloseOnQuit: 0
webWasm2023: 0
scriptingDefineSymbols:
Standalone: ENABLE_INPUT_SYSTEM;STARTER_ASSETS_PACKAGES_CHECKED
Standalone: ENABLE_INPUT_SYSTEM
additionalCompilerArguments: {}
platformArchitecture: {}
scriptingBackend:
@ -843,7 +843,7 @@ PlayerSettings:
suppressCommonWarnings: 1
allowUnsafeCode: 0
useDeterministicCompilation: 1
additionalIl2CppArgs:
additionalIl2CppArgs:
scriptingRuntimeVersion: 1
gcIncremental: 1
gcWBarrierValidation: 0
@ -852,15 +852,15 @@ PlayerSettings:
m_RenderingPath: 1
m_MobileRenderingPath: 1
metroPackageName: DistributedAuthoritySample
metroPackageVersion:
metroCertificatePath:
metroCertificatePassword:
metroCertificateSubject:
metroCertificateIssuer:
metroPackageVersion:
metroCertificatePath:
metroCertificatePassword:
metroCertificateSubject:
metroCertificateIssuer:
metroCertificateNotAfter: 0000000000000000
metroApplicationDescription: DistributedAuthoritySample
wsaImages: {}
metroTileShortName:
metroTileShortName:
metroTileShowName: 0
metroMediumTileShowName: 0
metroLargeTileShowName: 0
@ -875,23 +875,23 @@ PlayerSettings:
syncCapabilities: 0
platformCapabilities: {}
metroTargetDeviceFamilies: {}
metroFTAName:
metroFTAName:
metroFTAFileTypes: []
metroProtocolName:
vcxProjDefaultLanguage:
XboxOneProductId:
XboxOneUpdateKey:
XboxOneSandboxId:
XboxOneContentId:
XboxOneTitleId:
XboxOneSCId:
XboxOneGameOsOverridePath:
XboxOnePackagingOverridePath:
XboxOneAppManifestOverridePath:
metroProtocolName:
vcxProjDefaultLanguage:
XboxOneProductId:
XboxOneUpdateKey:
XboxOneSandboxId:
XboxOneContentId:
XboxOneTitleId:
XboxOneSCId:
XboxOneGameOsOverridePath:
XboxOnePackagingOverridePath:
XboxOneAppManifestOverridePath:
XboxOneVersion: 1.0.0.0
XboxOnePackageEncryption: 0
XboxOnePackageUpdateGranularity: 2
XboxOneDescription:
XboxOneDescription:
XboxOneLanguage:
- enus
XboxOneCapability: []
@ -904,36 +904,36 @@ PlayerSettings:
XboxOneAllowedProductIds: []
XboxOnePersistentLocalStorageSize: 0
XboxOneXTitleMemory: 8
XboxOneOverrideIdentityName:
XboxOneOverrideIdentityPublisher:
XboxOneOverrideIdentityName:
XboxOneOverrideIdentityPublisher:
vrEditorSettings: {}
cloudServicesEnabled: {}
luminIcon:
m_Name:
m_ModelFolderPath:
m_PortalFolderPath:
m_Name:
m_ModelFolderPath:
m_PortalFolderPath:
luminCert:
m_CertPath:
m_CertPath:
m_SignPackage: 1
luminIsChannelApp: 0
luminVersion:
m_VersionCode: 1
m_VersionName:
hmiPlayerDataPath:
m_VersionName:
hmiPlayerDataPath:
hmiForceSRGBBlit: 1
embeddedLinuxEnableGamepadInput: 0
hmiCpuConfiguration:
hmiCpuConfiguration:
hmiLogStartupTiming: 0
qnxGraphicConfPath:
qnxGraphicConfPath:
apiCompatibilityLevel: 6
captureStartupLogs: {}
activeInputHandler: 2
activeInputHandler: 1
windowsGamepadBackendHint: 0
cloudProjectId:
cloudProjectId:
framebufferDepthMemorylessMode: 0
qualitySettingsNames: []
projectName:
organizationId:
projectName:
organizationId:
cloudEnabled: 0
legacyClampBlendShapeWeights: 0
hmiLoadingImage: {fileID: 0}