fix Throwing pillow to not snap but still auto aim

Right joystick still rotates the player, but no longer snaps to a player.
Also, the auto-targeting is now used exlusively inside the Child's Throw
method. When throwing, it checks if there is a player in the direction the
player is pointing. If so, then the pillow is going this way, else it goes
in the Child's forward position.
This commit is contained in:
jparent 2015-08-23 13:46:54 -04:00
parent a2ebee6e24
commit 989342197c
4 changed files with 15 additions and 22 deletions

View File

@ -1070,7 +1070,6 @@ MonoBehaviour:
pillow: {fileID: 0}
Mom: {fileID: 0}
Animator: {fileID: 9580008}
target: {fileID: 0}
--- !u!114 &11446734
MonoBehaviour:
m_ObjectHideFlags: 1
@ -1094,7 +1093,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 567fe96dcacb08f4ab716a98ce99fc88, type: 3}
m_Name:
m_EditorClassIdentifier:
minAngleRange: 10
minAngleRange: 30
--- !u!135 &13545904
SphereCollider:
m_ObjectHideFlags: 1
@ -1248,7 +1247,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 0}
propertyPath: minAngleRange
value: 10
value: 30
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 0}

View File

@ -5,7 +5,7 @@ using System.Collections.Generic;
public class AutoTarget : MonoBehaviour
{
private List<Transform> targets;
public float minAngleRange = 20f;
public float minAngleRange = 30f;
// Use this for initialization
void Start ()

View File

@ -23,7 +23,6 @@ public class Child : MonoBehaviour
private bool _isSleeping;
private float _invulnerableTime;
private Bed _currentBed;
public Transform target;
private int _index;
private bool _isPushed = false;
@ -32,6 +31,8 @@ public class Child : MonoBehaviour
private float _stunTime;
private AutoTarget _autoTarget;
public int Index
{
get { return _index; }
@ -47,6 +48,7 @@ public class Child : MonoBehaviour
void Awake()
{
_rb = GetComponent<Rigidbody>();
_autoTarget = GetComponent<AutoTarget>();
}
void Update()
@ -54,11 +56,7 @@ public class Child : MonoBehaviour
Animator.SetBool("IsOnBed", GetBed());
_isGrounded = IsGrounded();
Debug.Log(_isGrounded);
// look at the target
if (target != null) {
transform.LookAt(target);
}
// We move the child depending on the camera orientation
@ -185,12 +183,14 @@ public class Child : MonoBehaviour
return colliders.Length > 0 ? colliders[0].GetComponent<Bed>() : null;
}
internal void Throw() {
public void Throw() {
if (pillow != null) {
Vector3 direction;
Transform target = _autoTarget.GetTarget(transform.forward);
if (target != null) {
direction = target.transform.position - pillow.transform.position;
}
@ -205,6 +205,8 @@ public class Child : MonoBehaviour
pillow.IsOwned = false;
pillow = null;
target = null;
}
}

View File

@ -75,22 +75,14 @@ public class ChildController : MonoBehaviour
}
if (xLookingValue != 0 || zLookingValue != 0) {
//Transform target = _autoTarget.GetTarget(new Vector3(xLookingValue, 0, zLookingValue));
Transform target = _autoTarget.GetTarget(xLookingValue, zLookingValue);
_child.target = target;
if (_child.target != null) {
transform.LookAt(_child.target);
}
else {
transform.eulerAngles = new Vector3(
transform.eulerAngles.x,
Mathf.Atan2(xLookingValue, zLookingValue) * Mathf.Rad2Deg -90, // -90 to correct forward facing angle...
transform.eulerAngles.z);
}
}
else {
_child.target = null; // no auto targeting when not actively pressing the joystick in a direction
// if player is not look with the right joystick, then face the direction we're going
// if left joystick is used, else we don't change the facing direction