mirror of
https://github.com/ConjureETS/PillowFight.git
synced 2026-03-25 17:40:59 +00:00
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:
parent
a2ebee6e24
commit
989342197c
@ -1070,7 +1070,6 @@ MonoBehaviour:
|
|||||||
pillow: {fileID: 0}
|
pillow: {fileID: 0}
|
||||||
Mom: {fileID: 0}
|
Mom: {fileID: 0}
|
||||||
Animator: {fileID: 9580008}
|
Animator: {fileID: 9580008}
|
||||||
target: {fileID: 0}
|
|
||||||
--- !u!114 &11446734
|
--- !u!114 &11446734
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 1
|
m_ObjectHideFlags: 1
|
||||||
@ -1094,7 +1093,7 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 567fe96dcacb08f4ab716a98ce99fc88, type: 3}
|
m_Script: {fileID: 11500000, guid: 567fe96dcacb08f4ab716a98ce99fc88, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
minAngleRange: 10
|
minAngleRange: 30
|
||||||
--- !u!135 &13545904
|
--- !u!135 &13545904
|
||||||
SphereCollider:
|
SphereCollider:
|
||||||
m_ObjectHideFlags: 1
|
m_ObjectHideFlags: 1
|
||||||
@ -1248,7 +1247,7 @@ Prefab:
|
|||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 0}
|
- target: {fileID: 0}
|
||||||
propertyPath: minAngleRange
|
propertyPath: minAngleRange
|
||||||
value: 10
|
value: 30
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
m_RemovedComponents: []
|
m_RemovedComponents: []
|
||||||
m_ParentPrefab: {fileID: 0}
|
m_ParentPrefab: {fileID: 0}
|
||||||
|
|||||||
@ -5,7 +5,7 @@ using System.Collections.Generic;
|
|||||||
public class AutoTarget : MonoBehaviour
|
public class AutoTarget : MonoBehaviour
|
||||||
{
|
{
|
||||||
private List<Transform> targets;
|
private List<Transform> targets;
|
||||||
public float minAngleRange = 20f;
|
public float minAngleRange = 30f;
|
||||||
|
|
||||||
// Use this for initialization
|
// Use this for initialization
|
||||||
void Start ()
|
void Start ()
|
||||||
|
|||||||
@ -23,7 +23,6 @@ public class Child : MonoBehaviour
|
|||||||
private bool _isSleeping;
|
private bool _isSleeping;
|
||||||
private float _invulnerableTime;
|
private float _invulnerableTime;
|
||||||
private Bed _currentBed;
|
private Bed _currentBed;
|
||||||
public Transform target;
|
|
||||||
|
|
||||||
private int _index;
|
private int _index;
|
||||||
private bool _isPushed = false;
|
private bool _isPushed = false;
|
||||||
@ -32,6 +31,8 @@ public class Child : MonoBehaviour
|
|||||||
|
|
||||||
private float _stunTime;
|
private float _stunTime;
|
||||||
|
|
||||||
|
private AutoTarget _autoTarget;
|
||||||
|
|
||||||
public int Index
|
public int Index
|
||||||
{
|
{
|
||||||
get { return _index; }
|
get { return _index; }
|
||||||
@ -47,6 +48,7 @@ public class Child : MonoBehaviour
|
|||||||
void Awake()
|
void Awake()
|
||||||
{
|
{
|
||||||
_rb = GetComponent<Rigidbody>();
|
_rb = GetComponent<Rigidbody>();
|
||||||
|
_autoTarget = GetComponent<AutoTarget>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update()
|
void Update()
|
||||||
@ -54,11 +56,7 @@ public class Child : MonoBehaviour
|
|||||||
Animator.SetBool("IsOnBed", GetBed());
|
Animator.SetBool("IsOnBed", GetBed());
|
||||||
|
|
||||||
_isGrounded = IsGrounded();
|
_isGrounded = IsGrounded();
|
||||||
Debug.Log(_isGrounded);
|
|
||||||
// look at the target
|
|
||||||
if (target != null) {
|
|
||||||
transform.LookAt(target);
|
|
||||||
}
|
|
||||||
|
|
||||||
// We move the child depending on the camera orientation
|
// 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;
|
return colliders.Length > 0 ? colliders[0].GetComponent<Bed>() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Throw() {
|
public void Throw() {
|
||||||
|
|
||||||
if (pillow != null) {
|
if (pillow != null) {
|
||||||
|
|
||||||
Vector3 direction;
|
Vector3 direction;
|
||||||
|
|
||||||
|
Transform target = _autoTarget.GetTarget(transform.forward);
|
||||||
|
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
direction = target.transform.position - pillow.transform.position;
|
direction = target.transform.position - pillow.transform.position;
|
||||||
}
|
}
|
||||||
@ -205,6 +205,8 @@ public class Child : MonoBehaviour
|
|||||||
pillow.IsOwned = false;
|
pillow.IsOwned = false;
|
||||||
|
|
||||||
pillow = null;
|
pillow = null;
|
||||||
|
|
||||||
|
target = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -75,22 +75,14 @@ public class ChildController : MonoBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (xLookingValue != 0 || zLookingValue != 0) {
|
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 = new Vector3(
|
||||||
transform.eulerAngles.x,
|
transform.eulerAngles.x,
|
||||||
Mathf.Atan2(xLookingValue, zLookingValue) * Mathf.Rad2Deg -90, // -90 to correct forward facing angle...
|
Mathf.Atan2(xLookingValue, zLookingValue) * Mathf.Rad2Deg -90, // -90 to correct forward facing angle...
|
||||||
transform.eulerAngles.z);
|
transform.eulerAngles.z);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
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 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
|
// if left joystick is used, else we don't change the facing direction
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user