mirror of
https://github.com/ConjureETS/PillowFight.git
synced 2026-03-24 00:50:59 +00:00
add Throwing of pillow and push back on hit
This commit is contained in:
parent
9af60216b6
commit
dcbf2df911
127
Assets/Prefabs/Pillow.prefab
Normal file
127
Assets/Prefabs/Pillow.prefab
Normal file
@ -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
|
||||
8
Assets/Prefabs/Pillow.prefab.meta
Normal file
8
Assets/Prefabs/Pillow.prefab.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a576af077db55e24b82098add55cc9dc
|
||||
timeCreated: 1440294303
|
||||
licenseType: Free
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -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"){
|
||||
|
||||
// picking up a pillow
|
||||
if (this.pillow == null && !other.GetComponent<Pillow>().IsThrown) {
|
||||
|
||||
pillow = other.GetComponent<Pillow>();
|
||||
other.transform.parent = transform; // make the pillow a child of Child
|
||||
|
||||
other.transform.localPosition = other.transform.position + transform.forward;
|
||||
other.GetComponent<Collider>().enabled = false;
|
||||
// TODO: place the pillow correctly or animate or something...
|
||||
}
|
||||
|
||||
//Debug.Log(_isGrounded);
|
||||
// getting hit by a pillow
|
||||
else if (other.GetComponent<Pillow>().IsThrown) {
|
||||
|
||||
//player is hit
|
||||
Debug.Log("Child is hit by a pillow");
|
||||
|
||||
Push( other.GetComponent<Rigidbody>().velocity.normalized * 10 * hitPushBackForce);
|
||||
Destroy(other.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -152,6 +168,27 @@ public class Child : MonoBehaviour
|
||||
return colliders.Length > 0 ? colliders[0].GetComponent<Bed>() : 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<Rigidbody>().isKinematic = false;
|
||||
pillow.GetComponent<Collider>().enabled = true;
|
||||
pillow.GetComponent<Rigidbody>().AddForce(direction * ThrowForce, ForceMode.Impulse);
|
||||
|
||||
pillow = null;
|
||||
}
|
||||
|
||||
|
||||
void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
if (collision.gameObject.tag == "Lava")
|
||||
|
||||
@ -111,6 +111,10 @@ public class ChildController : MonoBehaviour
|
||||
_child.WakeUp();
|
||||
InputManager.Instance.PushActiveContext("Awake", (int)PlayerNumber);
|
||||
}
|
||||
|
||||
if (input.Actions.Contains("Throw")) {
|
||||
_child.Throw();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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<Child>().takeHit();
|
||||
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user