Improve the throw mecanism with mecanim

This commit is contained in:
Patrice Vignola 2015-08-23 13:59:44 -04:00
parent 5bb2c06297
commit 17cae50b2d
7 changed files with 78 additions and 29 deletions

View File

@ -0,0 +1,13 @@
using UnityEngine;
using System.Collections;
public class MecanimContainer : MonoBehaviour
{
public Child ImmediateParent;
// For Mecanim
public void throw_pillow()
{
ImmediateParent.ThrowMecanimPillow();
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 4d248c94f1991a74ba25229de4e648ea
timeCreated: 1440351256
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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<Rigidbody>().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<Rigidbody>().velocity.normalized * 10 * hitPushBackForce);
Destroy(other.gameObject);
Push(other.GetComponent<Rigidbody>().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");
}
}

View File

@ -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<Collider>();