Working ragdoll; Added sounds bytes utils

This commit is contained in:
craftwill 2022-10-29 14:45:29 -04:00
parent 6535829abd
commit c7e2ba805b
15 changed files with 1281 additions and 117 deletions

13
Assets/FollowParent.cs Normal file
View File

@ -0,0 +1,13 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FollowParent : MonoBehaviour
{
[SerializeField] private Transform follow;
[SerializeField] private Rigidbody rg;
private void Update()
{
transform.position = follow.position;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0fbc699a0e80590478455ba80b87897b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -854,75 +854,6 @@ PrefabInstance:
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: f06e0b2bd426cc249b952a8f4e6711e5, type: 3}
--- !u!1001 &714208351
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 1211811540}
m_Modifications:
- target: {fileID: 8636591160554159306, guid: 7d85378c67373104c9c2627e9074c63d,
type: 3}
propertyPath: m_RootOrder
value: 2
objectReference: {fileID: 0}
- target: {fileID: 8636591160554159306, guid: 7d85378c67373104c9c2627e9074c63d,
type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8636591160554159306, guid: 7d85378c67373104c9c2627e9074c63d,
type: 3}
propertyPath: m_LocalPosition.y
value: -0.79
objectReference: {fileID: 0}
- target: {fileID: 8636591160554159306, guid: 7d85378c67373104c9c2627e9074c63d,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8636591160554159306, guid: 7d85378c67373104c9c2627e9074c63d,
type: 3}
propertyPath: m_LocalRotation.w
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8636591160554159306, guid: 7d85378c67373104c9c2627e9074c63d,
type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8636591160554159306, guid: 7d85378c67373104c9c2627e9074c63d,
type: 3}
propertyPath: m_LocalRotation.y
value: -1
objectReference: {fileID: 0}
- target: {fileID: 8636591160554159306, guid: 7d85378c67373104c9c2627e9074c63d,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8636591160554159306, guid: 7d85378c67373104c9c2627e9074c63d,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8636591160554159306, guid: 7d85378c67373104c9c2627e9074c63d,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: -180
objectReference: {fileID: 0}
- target: {fileID: 8636591160554159306, guid: 7d85378c67373104c9c2627e9074c63d,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8975820612264765040, guid: 7d85378c67373104c9c2627e9074c63d,
type: 3}
propertyPath: m_Name
value: Thief
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 7d85378c67373104c9c2627e9074c63d, type: 3}
--- !u!1001 &770064676
PrefabInstance:
m_ObjectHideFlags: 0
@ -2799,21 +2730,6 @@ PrefabInstance:
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 1772573266731274163, guid: 4dbf735f9da7b9f43b69f1577e4e5763,
type: 3}
propertyPath: movementSpeed
value: 0.8
objectReference: {fileID: 0}
- target: {fileID: 1772573266731274163, guid: 4dbf735f9da7b9f43b69f1577e4e5763,
type: 3}
propertyPath: maxMovementSpeed
value: 30
objectReference: {fileID: 0}
- target: {fileID: 1772573266731274169, guid: 4dbf735f9da7b9f43b69f1577e4e5763,
type: 3}
propertyPath: m_Enabled
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1772573266731274171, guid: 4dbf735f9da7b9f43b69f1577e4e5763,
type: 3}
propertyPath: m_Name
@ -2834,11 +2750,6 @@ PrefabInstance:
propertyPath: hitMarkerRect
value:
objectReference: {fileID: 1301531513}
- target: {fileID: 1772573266731274174, guid: 4dbf735f9da7b9f43b69f1577e4e5763,
type: 3}
propertyPath: m_IsKinematic
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1772573266731274175, guid: 4dbf735f9da7b9f43b69f1577e4e5763,
type: 3}
propertyPath: m_RootOrder
@ -2894,11 +2805,6 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1772573266917019329, guid: 4dbf735f9da7b9f43b69f1577e4e5763,
type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 4dbf735f9da7b9f43b69f1577e4e5763, type: 3}
--- !u!1001 &5226806889855461982

View File

@ -2,17 +2,21 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Bytes.Sound;
public class PlayerController : MonoBehaviour
{
private GrappleHook grappleScript;
private CharacterMovement movementScript;
private Rigidbody rb;
SoundPlayer soundPlayer;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
grappleScript = GetComponent<GrappleHook>();
movementScript = GetComponent<CharacterMovement>();
soundPlayer = GetComponent<SoundPlayer>();
}
// Update is called once per frame
@ -24,6 +28,7 @@ public class PlayerController : MonoBehaviour
public void Stun(float duration){
grappleScript.Stun(duration);
movementScript.Stun(duration);
soundPlayer.PlaySound("PlayerHurt");
}
public void Knockback(Vector2 dir){

View File

@ -13,25 +13,19 @@ public class Ragdoll : MonoBehaviour
{
[SerializeField]
private bool _startsRagdolled;
private List<Rigidbody> _ragdollRigidbodies;
private Animator _animator;
[SerializeField]
private Transform _hipBone;
private List<Rigidbody> _ragdollRigidbodies;
private bool _isRagdoll
{
get { return _ragdollRigidbodies != null && !_ragdollRigidbodies.Select(x => x.isKinematic).FirstOrDefault(); }
}
// Start is called before the first frame update
private void Start()
{
}
private void Awake()
{
_ragdollRigidbodies = GetComponentsInChildren<Rigidbody>().ToList();
_animator = GetComponent<Animator>();
_hipBone = _animator.GetBoneTransform(HumanBodyBones.Hips);
void setRagdollState()
{
@ -65,15 +59,19 @@ public class Ragdoll : MonoBehaviour
}
}
}
private void EnableRagdoll()
{
_ragdollRigidbodies.ForEach(rigidbody => rigidbody.isKinematic = false);
_animator.enabled = false;
}
private void DisableRagdoll()
{
_ragdollRigidbodies.ForEach(rigidbody => rigidbody.isKinematic = true);
_animator.enabled = true;
_ragdollRigidbodies.ForEach(rigidbody =>
{
rigidbody.isKinematic = true;
rigidbody.detectCollisions = true;
});
StandBackUp();
}
@ -95,6 +93,4 @@ public class Ragdoll : MonoBehaviour
_hipBone.position = originalHipsPosition;
}
}

View File

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

View File

@ -0,0 +1,37 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Bytes.Sound
{
[RequireComponent(typeof(AudioSource))]
public class SoundPlayer : MonoBehaviour
{
[SerializeField] private SoundTemplate[] playableSounds;
private Dictionary<string, SoundTemplate> _playableSounds;
private AudioSource _audioSource;
private void Awake()
{
_audioSource = GetComponent<AudioSource>();
_playableSounds = new Dictionary<string, SoundTemplate>();
foreach (var sound in playableSounds)
{
_playableSounds.Add(sound.name, sound);
}
}
public void PlaySound(string soundName, float volumeMultiplier = 1f, float overrideVolume = -1f)
{
if (_playableSounds.TryGetValue(soundName, out SoundTemplate sound))
{
_audioSource.clip = sound.GetRandomClip();
_audioSource.pitch = sound.GetRandomPitch();
_audioSource.volume = ((overrideVolume != -1f) ? overrideVolume : sound.volume) * volumeMultiplier;
_audioSource.Play();
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6fb36fee47a0d6a44bc2237dfbdac4d5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,29 @@
using System.Collections;
using UnityEngine;
namespace Bytes.Sound
{
[CreateAssetMenu(fileName = "Sound", menuName = "SoundTemplate")]
public class SoundTemplate : ScriptableObject
{
[Header("Text")]
public new string name;
[Header("Sound Data")]
[Tooltip("Sound variations if many.")]
public AudioClip[] clips;
public float volume = 1f;
[Tooltip("Max Random pitch change.")]
public float maxRandomPitchChange = 0.02f;
public AudioClip GetRandomClip()
{
return clips[Random.Range(0, clips.Length)];
}
public float GetRandomPitch()
{
return 1f + Random.Range(-maxRandomPitchChange, maxRandomPitchChange);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f5baf129b10beab41b82ab310fd176e2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,19 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f5baf129b10beab41b82ab310fd176e2, type: 3}
m_Name: SoundPlayerHurt
m_EditorClassIdentifier:
name: PlayerHurt
clips:
- {fileID: 0}
volume: 1
maxRandomPitchChange: 0.02

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 973ba6a42810a6b42807bf7ef7fe13a1
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -18,7 +18,7 @@ PhysicsManager:
m_ClothInterCollisionDistance: 0.1
m_ClothInterCollisionStiffness: 0.2
m_ContactsGeneration: 1
m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
m_LayerCollisionMatrix: fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdfffffffeffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
m_AutoSimulation: 1
m_AutoSyncTransforms: 0
m_ReuseCollisionCallbacks: 0

View File

@ -14,8 +14,8 @@ TagManager:
- UI
- Grappleable
- Stun
-
-
- Player
- PlayerRagdoll
-
-
-