Pickup Party, Physics! Part 3

This commit is contained in:
JesusLuvsYooh 2024-06-25 08:27:15 +01:00
parent 562f18d3f5
commit 24b5dab61c
6 changed files with 886 additions and 860 deletions

2
.gitignore vendored
View File

@ -81,3 +81,5 @@ Thumbs.db
# CompilationLog.txt created by tests
Assets/Mirror/Tests/Editor/Weaver/*/CompilationLog.txt
Assets/Mirage*
Assets/ParrelSync*

View File

@ -0,0 +1,135 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &3350161566424659706
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1357295079658837445}
- component: {fileID: 6414208444886493924}
- component: {fileID: 7067323468124357061}
- component: {fileID: 4167309113991024219}
- component: {fileID: 1373717341218114730}
m_Layer: 0
m_Name: PickupObject
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1357295079658837445
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3350161566424659706}
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 2.6, y: -0.41, z: 2.7}
m_LocalScale: {x: 0.5, y: 1, z: 0.5}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &6414208444886493924
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3350161566424659706}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &7067323468124357061
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3350161566424659706}
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_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 45d1084478c6d423da655089775d56a2, 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!65 &4167309113991024219
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3350161566424659706}
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: 3
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!54 &1373717341218114730
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3350161566424659706}
serializedVersion: 4
m_Mass: 1
m_Drag: 0.05
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: 0
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 1

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: ab3b3f71325c24893869dd9f6c9bf556
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -609,6 +609,7 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 6299839938573537759}
- component: {fileID: 1325586932094605749}
m_Layer: 0
m_Name: PlayerArmPivotL
m_TagString: Untagged
@ -633,6 +634,41 @@ Transform:
- {fileID: 3871552658736460632}
m_Father: {fileID: 3982489895616607845}
m_LocalEulerAnglesHint: {x: -45, y: -90, z: 0}
--- !u!114 &1325586932094605749
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3337348122071847668}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a553cb17010b2403e8523b558bffbc14, type: 3}
m_Name:
m_EditorClassIdentifier:
syncDirection: 1
syncMode: 0
syncInterval: 0
target: {fileID: 6299839938573537759}
syncPosition: 0
syncRotation: 1
syncScale: 0
onlySyncOnChange: 1
compressRotation: 1
interpolatePosition: 1
interpolateRotation: 1
interpolateScale: 0
coordinateSpace: 0
sendIntervalMultiplier: 3
timelineOffset: 0
showGizmos: 0
showOverlay: 0
overlayColor: {r: 0, g: 0, b: 0, a: 0.5}
bufferResetMultiplier: 6
changedDetection: 1
positionSensitivity: 0.01
rotationSensitivity: 0.5
scaleSensitivity: 0.01
--- !u!1 &3505744635913726724
GameObject:
m_ObjectHideFlags: 0
@ -792,7 +828,7 @@ MonoBehaviour:
compressRotation: 1
interpolatePosition: 1
interpolateRotation: 1
interpolateScale: 1
interpolateScale: 0
coordinateSpace: 0
sendIntervalMultiplier: 3
timelineOffset: 0
@ -862,7 +898,7 @@ MonoBehaviour:
playerArmSlots:
- {fileID: 3397797976900785828}
- {fileID: 1009485556880835443}
freezeRBrotation: 1
freezePositionRB: 1
characterController: {fileID: 4117093369808553598}
--- !u!1 &5473584597135620801
GameObject:
@ -1160,6 +1196,7 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 2672433250560454}
- component: {fileID: 7204149903870050621}
m_Layer: 0
m_Name: PlayerArmPivotR
m_TagString: Untagged
@ -1184,6 +1221,41 @@ Transform:
- {fileID: 6532467146160453607}
m_Father: {fileID: 3982489895616607845}
m_LocalEulerAnglesHint: {x: -45, y: 90, z: 0}
--- !u!114 &7204149903870050621
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8085302157987762566}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a553cb17010b2403e8523b558bffbc14, type: 3}
m_Name:
m_EditorClassIdentifier:
syncDirection: 1
syncMode: 0
syncInterval: 0
target: {fileID: 2672433250560454}
syncPosition: 0
syncRotation: 1
syncScale: 0
onlySyncOnChange: 1
compressRotation: 1
interpolatePosition: 1
interpolateRotation: 1
interpolateScale: 0
coordinateSpace: 0
sendIntervalMultiplier: 3
timelineOffset: 0
showGizmos: 0
showOverlay: 0
overlayColor: {r: 0, g: 0, b: 0, a: 0.5}
bufferResetMultiplier: 6
changedDetection: 1
positionSensitivity: 0.01
rotationSensitivity: 0.5
scaleSensitivity: 0.01
--- !u!1 &8909848922143598225
GameObject:
m_ObjectHideFlags: 0

View File

@ -14,11 +14,11 @@ public class PlayerPickupParty : NetworkBehaviour
private float verticalSpeed = 0f;
public float armRotationSpeed = 25f;
public bool canPickup = false;
public Transform[] pickedUpObjects; // acts like inventory slots
public Rigidbody[] pickedUpRigidbodies; // cache pickups
public Transform[] pickedUpObjects; // store pickups like an inventory
public Rigidbody[] pickedUpRigidbodies; // cache pickups to avoid re-referencing and get components
public Transform[] armPivots; // acts like inventory slots
public PlayerArmSlot[] playerArmSlots; // acts like inventory slots
public bool freezeRBrotation = true;
public bool freezeRotationRB = true; // if false, picked up objects rotate with collision
public CharacterController characterController;
private Camera mainCamera;
@ -93,10 +93,8 @@ void PlayerMovement()
}
#endif
#if !UNITY_SERVER
[ClientCallback]
[ClientCallback]
void RotatePlayerToMouse()
{
Plane playerPlane = new Plane(Vector3.up, transform.position);
@ -118,12 +116,12 @@ void RotateArmsToMouse()
if (slotActive == 0)
{
Quaternion defaultArmRotation = Quaternion.Euler(-45, -90, 0);
armPivots[1].localRotation = Quaternion.Slerp(armPivots[1].localRotation, defaultArmRotation, (armRotationSpeed/5) * Time.deltaTime);
armPivots[1].localRotation = Quaternion.Slerp(armPivots[1].localRotation, defaultArmRotation, (armRotationSpeed / 5) * Time.deltaTime);
}
else
{
Quaternion defaultArmRotation = Quaternion.Euler(-45, 90, 0);
armPivots[0].localRotation = Quaternion.Slerp(armPivots[0].localRotation, defaultArmRotation, (armRotationSpeed/5) * Time.deltaTime);
armPivots[0].localRotation = Quaternion.Slerp(armPivots[0].localRotation, defaultArmRotation, (armRotationSpeed / 5) * Time.deltaTime);
}
Vector3 mouseScreenPosition = Input.mousePosition;
@ -152,19 +150,19 @@ void Pickup()
pickedUpObjects[slotActive].SetParent(armPivots[slotActive]);
//pickedUpObjectRigidbody.isKinematic = true;
pickedUpRigidbodies[slotActive].useGravity = false;
if (freezeRBrotation)
if (freezeRotationRB)
{
pickedUpRigidbodies[slotActive].constraints = RigidbodyConstraints.FreezePosition;
pickedUpRigidbodies[slotActive].constraints = RigidbodyConstraints.FreezeRotation;
}
playerArmSlots[slotActive].triggerCollider.enabled = false;
canPickup = false;
}
else if(pickedUpObjects[slotActive] != null)
else if (pickedUpObjects[slotActive] != null)
{
pickedUpObjects[slotActive].SetParent(null);
//pickedUpObjectRigidbody.isKinematic = false;
pickedUpRigidbodies[slotActive].useGravity = true;
if (freezeRBrotation)
if (freezeRotationRB)
{
pickedUpRigidbodies[slotActive].constraints = RigidbodyConstraints.None;
}