diff --git a/Assets/Prefabs/Pillow.prefab b/Assets/Prefabs/Pillow.prefab new file mode 100644 index 0000000..c15055a --- /dev/null +++ b/Assets/Prefabs/Pillow.prefab @@ -0,0 +1,127 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &146860 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + serializedVersion: 4 + m_Component: + - 4: {fileID: 448838} + - 33: {fileID: 3385352} + - 23: {fileID: 2308174} + - 54: {fileID: 5489500} + - 135: {fileID: 13538950} + - 114: {fileID: 11461144} + m_Layer: 0 + m_Name: Pillow + m_TagString: Pillow + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &448838 +Transform: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 146860} + m_LocalRotation: {x: -.707106829, y: 0, z: -0, w: .707106829} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 +--- !u!23 &2308174 +MeshRenderer: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 146860} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_Materials: + - {fileID: 2100000, guid: fbc6b255d0260d4488f0a8f51896a937, type: 2} + m_SubsetIndices: + m_StaticBatchRoot: {fileID: 0} + m_UseLightProbes: 1 + m_ReflectionProbeUsage: 1 + m_ProbeAnchor: {fileID: 0} + m_ScaleInLightmap: 1 + m_PreserveUVs: 0 + m_ImportantGI: 0 + m_AutoUVMaxDistance: .5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingOrder: 0 +--- !u!33 &3385352 +MeshFilter: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 146860} + m_Mesh: {fileID: 4300000, guid: 5f25e7658d2291248b5b733de46d36c1, type: 3} +--- !u!54 &5489500 +Rigidbody: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 146860} + serializedVersion: 2 + m_Mass: 1 + m_Drag: 0 + m_AngularDrag: .0500000007 + m_UseGravity: 1 + m_IsKinematic: 1 + m_Interpolate: 0 + m_Constraints: 0 + m_CollisionDetection: 0 +--- !u!114 &11461144 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 146860} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e000b2f669ba4344490c42914fbad190, type: 3} + m_Name: + m_EditorClassIdentifier: + IsThrown: 0 +--- !u!135 &13538950 +SphereCollider: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 146860} + m_Material: {fileID: 0} + m_IsTrigger: 1 + m_Enabled: 1 + serializedVersion: 2 + m_Radius: .419999987 + m_Center: {x: 0, y: 0, z: 0} +--- !u!1001 &100100000 +Prefab: + m_ObjectHideFlags: 1 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 0} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_ParentPrefab: {fileID: 0} + m_RootGameObject: {fileID: 146860} + m_IsPrefabParent: 1 diff --git a/Assets/Prefabs/Pillow.prefab.meta b/Assets/Prefabs/Pillow.prefab.meta new file mode 100644 index 0000000..95a2a6e --- /dev/null +++ b/Assets/Prefabs/Pillow.prefab.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a576af077db55e24b82098add55cc9dc +timeCreated: 1440294303 +licenseType: Free +NativeFormatImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Child.cs b/Assets/Scripts/Child.cs index 9220d97..1782642 100644 --- a/Assets/Scripts/Child.cs +++ b/Assets/Scripts/Child.cs @@ -7,6 +7,9 @@ public class Child : MonoBehaviour public float Speed = 10f; public float JumpForce = 10f; public float MaxInvulnerableTime = 2f; + public float ThrowForce = 30f; + public float hitPushBackForce = 250f; + public GameObject GroundCheck; public Pillow pillow; public MomBehavior Mom; @@ -51,14 +54,27 @@ public class Child : MonoBehaviour } void OnTriggerEnter(Collider other) { - if (other.tag == "Pillow") { + if (other.tag == "Pillow"){ - pillow = other.GetComponent(); - other.transform.parent = transform; // make the pillow a child of Child - - // TODO: place the pillow correctly or animate or something... + // picking up a pillow + if (this.pillow == null && !other.GetComponent().IsThrown) { - //Debug.Log(_isGrounded); + pillow = other.GetComponent(); + other.transform.parent = transform; // make the pillow a child of Child + other.transform.localPosition = other.transform.position + transform.forward; + other.GetComponent().enabled = false; + // TODO: place the pillow correctly or animate or something... + } + + // getting hit by a pillow + else if (other.GetComponent().IsThrown) { + + //player is hit + Debug.Log("Child is hit by a pillow"); + + Push( other.GetComponent().velocity.normalized * 10 * hitPushBackForce); + Destroy(other.gameObject); + } } } @@ -152,6 +168,27 @@ public class Child : MonoBehaviour return colliders.Length > 0 ? colliders[0].GetComponent() : null; } + internal void Throw() { + Vector3 direction; + if (target != null) { + direction = target.transform.position - pillow.transform.position; + } + else { + direction = transform.forward; + } + direction = direction.normalized; + + + pillow.IsThrown = true; + pillow.transform.parent = null; // detach the pillow from the child object + pillow.GetComponent().isKinematic = false; + pillow.GetComponent().enabled = true; + pillow.GetComponent().AddForce(direction * ThrowForce, ForceMode.Impulse); + + pillow = null; + } + + void OnCollisionEnter(Collision collision) { if (collision.gameObject.tag == "Lava") diff --git a/Assets/Scripts/ChildController.cs b/Assets/Scripts/ChildController.cs index 2721ed7..bde9551 100644 --- a/Assets/Scripts/ChildController.cs +++ b/Assets/Scripts/ChildController.cs @@ -85,7 +85,7 @@ public class ChildController : MonoBehaviour else { transform.eulerAngles = new Vector3( transform.eulerAngles.x, - Mathf.Atan2(xLookingValue, zLookingValue) * Mathf.Rad2Deg, + Mathf.Atan2(xLookingValue, zLookingValue) * Mathf.Rad2Deg -90, // -90 to correct forward facing angle... transform.eulerAngles.z); } } @@ -111,6 +111,10 @@ public class ChildController : MonoBehaviour _child.WakeUp(); InputManager.Instance.PushActiveContext("Awake", (int)PlayerNumber); } + + if (input.Actions.Contains("Throw")) { + _child.Throw(); + } } } diff --git a/Assets/Scripts/Pillow.cs b/Assets/Scripts/Pillow.cs index 22c8f03..e9fb8ee 100644 --- a/Assets/Scripts/Pillow.cs +++ b/Assets/Scripts/Pillow.cs @@ -15,17 +15,6 @@ public class Pillow : MonoBehaviour { if (transform.position.y < -10) { Destroy(this.gameObject); } + } - - void OnTriggerEnter(Collider other) { - if (IsThrown && other.tag == "Player") { - - Debug.Log("A child got hit by a pillow!"); - - //other.GetComponent().takeHit(); - - Destroy(this.gameObject); - } - } - }