mirror of
https://github.com/ConjureETS/PillowFight.git
synced 2026-03-24 00:50:59 +00:00
Merge branch 'master' of https://github.com/conjureets/pillowfight
This commit is contained in:
commit
010fb31b29
Binary file not shown.
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f6d5f460fe8d6bc479da1b6305919ede
|
||||
timeCreated: 1440209848
|
||||
licenseType: Free
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -5,8 +5,13 @@ using System.Collections;
|
||||
public class Child : MonoBehaviour
|
||||
{
|
||||
public float Speed = 10f;
|
||||
public float JumpForce = 10f;
|
||||
public GameObject GroundCheck;
|
||||
|
||||
private Rigidbody _rb;
|
||||
private bool _isGrounded = false;
|
||||
private float _xValue;
|
||||
private float _zValue;
|
||||
public Pillow pillow;
|
||||
|
||||
|
||||
@ -15,6 +20,12 @@ public class Child : MonoBehaviour
|
||||
_rb = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
_isGrounded = IsGrounded();
|
||||
|
||||
Debug.Log(_isGrounded);
|
||||
}
|
||||
|
||||
|
||||
void OnTriggerEnter(Collider other) {
|
||||
@ -25,22 +36,46 @@ public class Child : MonoBehaviour
|
||||
|
||||
// TODO: place the pillow correctly or animate or something...
|
||||
|
||||
Debug.Log(_isGrounded);
|
||||
}
|
||||
}
|
||||
|
||||
public void Move(float xValue, float zValue)
|
||||
void FixedUpdate()
|
||||
{
|
||||
// We move the child depending on the camera orientation
|
||||
|
||||
Vector3 forwardDir = Camera.main.transform.forward;
|
||||
Vector3 rightDir = Camera.main.transform.right;
|
||||
|
||||
forwardDir.y = 0f;
|
||||
forwardDir *= zValue * Speed;
|
||||
forwardDir *= _zValue * Speed;
|
||||
forwardDir.y = _rb.velocity.y;
|
||||
|
||||
rightDir *= _xValue * Speed;
|
||||
rightDir.y = 0f;
|
||||
rightDir *= xValue * Speed;
|
||||
|
||||
_rb.velocity = forwardDir + rightDir;
|
||||
}
|
||||
|
||||
private bool IsGrounded()
|
||||
{
|
||||
Collider[] colliders = Physics.OverlapSphere(GroundCheck.transform.position, 0.5f, 1 << LayerMask.NameToLayer("Ground"));
|
||||
|
||||
return colliders.Length > 0;
|
||||
}
|
||||
|
||||
public void Move(float xValue, float zValue)
|
||||
{
|
||||
_xValue = xValue;
|
||||
_zValue = zValue;
|
||||
}
|
||||
|
||||
public void Jump()
|
||||
{
|
||||
if (_isGrounded)
|
||||
{
|
||||
_isGrounded = false;
|
||||
|
||||
_rb.AddForce(new Vector3(0f, JumpForce, 0f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,12 +14,13 @@ public class ChildController : MonoBehaviour
|
||||
void Awake()
|
||||
{
|
||||
InputManager.Instance.PushActiveContext("Gameplay", (int)PlayerNumber);
|
||||
InputManager.Instance.AddCallback((int)PlayerNumber, HandlePlayerInput);
|
||||
InputManager.Instance.AddCallback((int)PlayerNumber, HandlePlayerAxis);
|
||||
InputManager.Instance.AddCallback((int)PlayerNumber, HandlePlayerButtons);
|
||||
|
||||
_child = GetComponent<Child>();
|
||||
}
|
||||
|
||||
private void HandlePlayerInput(MappedInput input)
|
||||
private void HandlePlayerAxis(MappedInput input)
|
||||
{
|
||||
if (this == null) return;
|
||||
|
||||
@ -48,4 +49,14 @@ public class ChildController : MonoBehaviour
|
||||
_child.Move(xValue, zValue);
|
||||
}
|
||||
|
||||
private void HandlePlayerButtons(MappedInput input)
|
||||
{
|
||||
if (this == null) return;
|
||||
|
||||
if (input.Actions.Contains("Jump"))
|
||||
{
|
||||
_child.Jump();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user