From 17cae50b2d53cb6301a068957806a7d8e3d75df5 Mon Sep 17 00:00:00 2001 From: Patrice Vignola Date: Sun, 23 Aug 2015 13:59:44 -0400 Subject: [PATCH] Improve the throw mecanism with mecanim --- Assets/MecanimContainer.cs | 13 ++++++ Assets/MecanimContainer.cs.meta | 12 ++++++ Assets/Prefabs/Child.prefab | 15 ++++++- Assets/Prefabs/Kid_AnimControl.controller | 2 +- Assets/Scenes/Gameplay.unity | 4 -- Assets/Scripts/Child.cs | 52 +++++++++++++---------- Assets/Scripts/Pillow.cs | 9 ++++ 7 files changed, 78 insertions(+), 29 deletions(-) create mode 100644 Assets/MecanimContainer.cs create mode 100644 Assets/MecanimContainer.cs.meta diff --git a/Assets/MecanimContainer.cs b/Assets/MecanimContainer.cs new file mode 100644 index 0000000..86bbf21 --- /dev/null +++ b/Assets/MecanimContainer.cs @@ -0,0 +1,13 @@ +using UnityEngine; +using System.Collections; + +public class MecanimContainer : MonoBehaviour +{ + public Child ImmediateParent; + + // For Mecanim + public void throw_pillow() + { + ImmediateParent.ThrowMecanimPillow(); + } +} diff --git a/Assets/MecanimContainer.cs.meta b/Assets/MecanimContainer.cs.meta new file mode 100644 index 0000000..c9daa61 --- /dev/null +++ b/Assets/MecanimContainer.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 4d248c94f1991a74ba25229de4e648ea +timeCreated: 1440351256 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/Child.prefab b/Assets/Prefabs/Child.prefab index c8330af..09df4f7 100644 --- a/Assets/Prefabs/Child.prefab +++ b/Assets/Prefabs/Child.prefab @@ -417,6 +417,7 @@ GameObject: m_Component: - 4: {fileID: 436644} - 95: {fileID: 9580008} + - 114: {fileID: 11484968} m_Layer: 0 m_Name: Container m_TagString: Untagged @@ -1084,7 +1085,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: e6ffb35a11ff1f545ac22f7ea752cffb, type: 3} m_Name: m_EditorClassIdentifier: - PlayerNumber: 1 + PlayerNumber: 0 --- !u!114 &11474836 MonoBehaviour: m_ObjectHideFlags: 1 @@ -1097,6 +1098,18 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: minAngleRange: 10 +--- !u!114 &11484968 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 166010} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4d248c94f1991a74ba25229de4e648ea, type: 3} + m_Name: + m_EditorClassIdentifier: + ImmediateParent: {fileID: 11430644} --- !u!135 &13545904 SphereCollider: m_ObjectHideFlags: 1 diff --git a/Assets/Prefabs/Kid_AnimControl.controller b/Assets/Prefabs/Kid_AnimControl.controller index fe32a51..789e89b 100644 --- a/Assets/Prefabs/Kid_AnimControl.controller +++ b/Assets/Prefabs/Kid_AnimControl.controller @@ -70,7 +70,7 @@ AnimatorStateTransition: m_TransitionDuration: .25 m_TransitionOffset: 0 m_ExitTime: .659090877 - m_HasExitTime: 1 + m_HasExitTime: 0 m_HasFixedDuration: 1 m_InterruptionSource: 0 m_OrderedInterruption: 1 diff --git a/Assets/Scenes/Gameplay.unity b/Assets/Scenes/Gameplay.unity index 9dfd389..7264140 100644 --- a/Assets/Scenes/Gameplay.unity +++ b/Assets/Scenes/Gameplay.unity @@ -2595,10 +2595,6 @@ Prefab: propertyPath: m_Name value: Child 1 objectReference: {fileID: 0} - - target: {fileID: 11446734, guid: 6dd661a967968c64dbae75c01fac6a09, type: 2} - propertyPath: PlayerNumber - value: 0 - objectReference: {fileID: 0} m_RemovedComponents: [] m_ParentPrefab: {fileID: 100100000, guid: 6dd661a967968c64dbae75c01fac6a09, type: 2} m_IsPrefabParent: 0 diff --git a/Assets/Scripts/Child.cs b/Assets/Scripts/Child.cs index 1ace8c5..fd7a57a 100644 --- a/Assets/Scripts/Child.cs +++ b/Assets/Scripts/Child.cs @@ -116,6 +116,25 @@ public class Child : MonoBehaviour } } + public void ThrowMecanimPillow() + { + Vector3 direction = target == null ? direction = transform.forward : target.transform.position - pillow.transform.position; + + direction = direction.normalized; + + pillow.gameObject.SetActive(true); + pillow.transform.localPosition = new Vector3(0.109f, -0.407f, 0.389f); + pillow.transform.localEulerAngles = new Vector3(0f, 204.46f, 310.0002f); + + AnimationPillow.SetActive(false); + + pillow.Throw(direction * ThrowForce); + + pillow.IsOwned = false; + + pillow = null; + } + void OnTriggerEnter(Collider other) { if (other.tag == "Pillow"){ @@ -127,9 +146,11 @@ public class Child : MonoBehaviour pillow = incomingPillow; pillow.transform.parent = transform; // make the pillow a child of Child - pillow.transform.localPosition = new Vector3(0f, 1.5f, 0f); + pillow.gameObject.SetActive(false); pillow.GetComponent().isKinematic = true; // dont make pillow obey to gravity when in a child's hands pillow.IsOwned = true; + pillow.Owner = this; + AnimationPillow.SetActive(true); // TODO: place the pillow correctly or animate or something... } @@ -137,11 +158,14 @@ public class Child : MonoBehaviour // getting hit by a pillow else if (incomingPillow.IsThrown) { - //player is hit - Debug.Log("Child is hit by a pillow"); + if (pillow.Owner != null && pillow.Owner != this) + { + //player is hit + Debug.Log("Child is hit by a pillow"); - Push( other.GetComponent().velocity.normalized * 10 * hitPushBackForce); - Destroy(other.gameObject); + Push(other.GetComponent().velocity.normalized * 10 * hitPushBackForce); + Destroy(other.gameObject); + } } } } @@ -209,24 +233,6 @@ public class Child : MonoBehaviour if (_isInLava) return; if (pillow != null) { - - Vector3 direction; - - if (target != null) { - direction = target.transform.position - pillow.transform.position; - } - else { - direction = transform.forward; - } - direction = direction.normalized; - - - pillow.Throw(direction * ThrowForce); - - pillow.IsOwned = false; - - pillow = null; - Animator.SetTrigger("StartAttack"); } } diff --git a/Assets/Scripts/Pillow.cs b/Assets/Scripts/Pillow.cs index 6c9cf1b..7b148c9 100644 --- a/Assets/Scripts/Pillow.cs +++ b/Assets/Scripts/Pillow.cs @@ -31,6 +31,15 @@ public class Pillow : MonoBehaviour { } } + private Child _owner; + + public Child Owner + { + get { return _owner; } + set { _owner = value; } + } + + // Use this for initialization void Start () { _col = GetComponent();