Commit c45115d7 authored by Unknown's avatar Unknown
Browse files

Doppel Jump sollte mit Air charges funktionieren

parent 62e2b8e7
...@@ -13,7 +13,7 @@ MonoBehaviour: ...@@ -13,7 +13,7 @@ MonoBehaviour:
m_Name: Movement States m_Name: Movement States
m_EditorClassIdentifier: Assembly-CSharp:_Game.Scripts.Scriptable_Object:MovementStates m_EditorClassIdentifier: Assembly-CSharp:_Game.Scripts.Scriptable_Object:MovementStates
airMoveState: airMoveState:
jumpForce: 5 jumpForce: 10
smoothing: 0.03 smoothing: 0.03
airControl: 1 airControl: 1
canSwim: 1 canSwim: 1
...@@ -49,11 +49,11 @@ MonoBehaviour: ...@@ -49,11 +49,11 @@ MonoBehaviour:
mass: 1 mass: 1
gravity: 3 gravity: 3
defaultMoveState: defaultMoveState:
jumpForce: 0 jumpForce: 10
smoothing: 0 smoothing: 0.03
airControl: 0 airControl: 1
canSwim: 0 canSwim: 1
moveSpeed: 0 moveSpeed: 20
maxJumpCount: 0 maxJumpCount: 1
mass: 0 mass: 1
gravity: 0 gravity: 1
...@@ -12,14 +12,15 @@ MonoBehaviour: ...@@ -12,14 +12,15 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 353b156b7c59b1c45a8767d7500b31fb, type: 3} m_Script: {fileID: 11500000, guid: 353b156b7c59b1c45a8767d7500b31fb, type: 3}
m_Name: PlayerState m_Name: PlayerState
m_EditorClassIdentifier: m_EditorClassIdentifier:
currentInfusedElement: 2 currentInfusedElement: 0
currentMoveState: currentMoveState:
jumpForce: 0 jumpForce: 10
smoothing: 0 smoothing: 0.03
airControl: 0 airControl: 1
moveSpeed: 0 canSwim: 1
maxJumpCount: 0 moveSpeed: 30
mass: 0 maxJumpCount: 5
gravity: 0 mass: 0.1
gravity: 0.5
movementStates: {fileID: 11400000, guid: c757aad6925b37a46b916f609fa9012b, type: 2} movementStates: {fileID: 11400000, guid: c757aad6925b37a46b916f609fa9012b, type: 2}
charges: 4 charges: 0
...@@ -5,11 +5,11 @@ using UnityEngine; ...@@ -5,11 +5,11 @@ using UnityEngine;
[RequireComponent(typeof(MovementController))] [RequireComponent(typeof(MovementController))]
public class InputController : MonoBehaviour { public class InputController : MonoBehaviour {
private MovementController m_Controller; private MovementController m_Controller;
private float m_XAxis, m_YAxis; private float m_XAxis, m_YAxis;
private bool m_Jump = false; private bool m_Jump = false;
void Start () { void Start () {
//Sucht nach MovementController auf dem selben Gameobject //Sucht nach MovementController auf dem selben Gameobject
m_Controller = GetComponent<MovementController>(); m_Controller = GetComponent<MovementController>();
} }
...@@ -24,4 +24,4 @@ public class InputController : MonoBehaviour { ...@@ -24,4 +24,4 @@ public class InputController : MonoBehaviour {
//Ruft Move Methode im MovementController auf dient der Bewegung des Charakters //Ruft Move Methode im MovementController auf dient der Bewegung des Charakters
m_Controller.Move(new Vector2(m_XAxis, m_YAxis), m_Jump); m_Controller.Move(new Vector2(m_XAxis, m_YAxis), m_Jump);
} }
} }
\ No newline at end of file
...@@ -17,8 +17,9 @@ public class MovementController : MonoBehaviour ...@@ -17,8 +17,9 @@ public class MovementController : MonoBehaviour
[SerializeField] private bool m_AirControl = false; // Whether or not a player can steer while jumping; [SerializeField] private bool m_AirControl = false; // Whether or not a player can steer while jumping;
[SerializeField] private bool m_CanSwim = true; [SerializeField] private bool m_CanSwim = true;
[Header("Ground Check Control")] [Header("Ground Check Control")] [SerializeField]
[SerializeField] private LayerMask m_WhatIsGround; // A mask determining what is ground to the character private LayerMask m_WhatIsGround; // A mask determining what is ground to the character
[SerializeField] private Transform m_GroundCheck; // A position marking where to check if the player is grounded. [SerializeField] private Transform m_GroundCheck; // A position marking where to check if the player is grounded.
[SerializeField] private float m_GroundCheckDistance = 1.5f; [SerializeField] private float m_GroundCheckDistance = 1.5f;
[SerializeField] private float m_GroundedRadius = .2f; [SerializeField] private float m_GroundedRadius = .2f;
...@@ -47,19 +48,6 @@ public class MovementController : MonoBehaviour ...@@ -47,19 +48,6 @@ public class MovementController : MonoBehaviour
public UnityEvent OnSwimEvent; public UnityEvent OnSwimEvent;
public UnityEvent OnJumpEvent; public UnityEvent OnJumpEvent;
public void SetMovementParameters(MovementState state)
{
m_JumpForce = state.jumpForce;
m_MovementSmoothing = state.smoothing;
m_AirControl = state.airControl;
m_CanSwim = state.canSwim;
m_Speed = state.moveSpeed;
m_MaxJumpCount = state.maxJumpCount;
m_Rigidbody2D.mass = state.mass;
m_Rigidbody2D.gravityScale = state.gravity;
}
private void Awake() private void Awake()
{ {
m_Rigidbody2D = GetComponent<Rigidbody2D>(); m_Rigidbody2D = GetComponent<Rigidbody2D>();
...@@ -96,7 +84,15 @@ public class MovementController : MonoBehaviour ...@@ -96,7 +84,15 @@ public class MovementController : MonoBehaviour
if (m_RaycastHits2D[i].transform.gameObject == gameObject) continue; if (m_RaycastHits2D[i].transform.gameObject == gameObject) continue;
m_Grounded = true; m_Grounded = true;
m_TempJumpCount = m_MaxJumpCount; if (r_State.GetCurrentElement() != InfusedElement.Air)
{
m_TempJumpCount = m_MaxJumpCount;
}
else
{
m_TempJumpCount = r_State.GetCharges();
}
m_CurrentGroundNormal = m_RaycastHits2D[i].normal; m_CurrentGroundNormal = m_RaycastHits2D[i].normal;
if (!wasGrounded) if (!wasGrounded)
{ {
...@@ -106,11 +102,9 @@ public class MovementController : MonoBehaviour ...@@ -106,11 +102,9 @@ public class MovementController : MonoBehaviour
} }
public void Move(Vector2 move, bool jump) public void Move(Vector2 move, bool jump)
{ {
Debug.Log("Temp Jump: " + m_TempJumpCount + " Air charges: " + r_State.GetCharges());
Debug.Log("grounded: " + m_Grounded + " aircontrol: " + m_AirControl);
//only control the player if grounded or airControl is turned on //only control the player if grounded or airControl is turned on
if (m_Grounded || (m_AirControl && (m_Airborn && !m_Grounded)) || (m_Swimming && m_CanSwim)) if (m_Grounded || (m_AirControl && (m_Airborn && !m_Grounded)) || (m_Swimming && m_CanSwim))
{ {
...@@ -138,12 +132,18 @@ public class MovementController : MonoBehaviour ...@@ -138,12 +132,18 @@ public class MovementController : MonoBehaviour
// If the player should jump... // If the player should jump...
if (jump) if (jump)
{ {
if (((m_Grounded) || (m_TempJumpCount > 1) || (m_Swimming && m_CanSwim)) && !m_Jumped) if (m_Grounded || (m_Swimming && m_CanSwim) && !m_Jumped)
{
m_Grounded = false;
m_Rigidbody2D.velocity = Vector2.up * m_JumpForce;
OnJumpEvent.Invoke();
StartCoroutine(Wait(m_SecondsWaitToJump));
}
else if ((m_TempJumpCount > 0) && !m_Jumped)
{ {
// Add a vertical force to the player.
m_Grounded = false; m_Grounded = false;
m_TempJumpCount--; m_TempJumpCount--;
//m_Rigidbody2D.AddForce (new Vector2 (0f, m_JumpForce)); if (r_State.GetCurrentElement() == InfusedElement.Air) r_State.ChangeCharges(-1);
m_Rigidbody2D.velocity = Vector2.up * m_JumpForce; m_Rigidbody2D.velocity = Vector2.up * m_JumpForce;
OnJumpEvent.Invoke(); OnJumpEvent.Invoke();
StartCoroutine(Wait(m_SecondsWaitToJump)); StartCoroutine(Wait(m_SecondsWaitToJump));
...@@ -154,10 +154,23 @@ public class MovementController : MonoBehaviour ...@@ -154,10 +154,23 @@ public class MovementController : MonoBehaviour
{ {
m_Rigidbody2D.velocity += Vector2.up * Physics2D.gravity.y * (m_fallMultiplier - 1) * Time.deltaTime; m_Rigidbody2D.velocity += Vector2.up * Physics2D.gravity.y * (m_fallMultiplier - 1) * Time.deltaTime;
} }
//else if (m_Rigidbody2D.velocity.y > 0 && !Input.GetButton("Jump")) else if (m_Rigidbody2D.velocity.y > 0 && !Input.GetButton("Jump"))
//{ {
// m_Rigidbody2D.velocity += Vector2.up * Physics2D.gravity.y * (m_lowJumpMultiplier - 1) * Time.deltaTime; m_Rigidbody2D.velocity += Vector2.up * Physics2D.gravity.y * (m_lowJumpMultiplier - 1) * Time.deltaTime;
//} }
}
public void UpdateMovementParameters()
{
MovementState state = r_State.GetCurrentMovementState();
m_JumpForce = state.jumpForce;
m_MovementSmoothing = state.smoothing;
m_AirControl = state.airControl;
m_CanSwim = state.canSwim;
m_Speed = state.moveSpeed;
m_MaxJumpCount = state.maxJumpCount;
m_Rigidbody2D.mass = state.mass;
m_Rigidbody2D.gravityScale = state.gravity;
} }
public void SetSwimming(bool value) public void SetSwimming(bool value)
...@@ -180,6 +193,12 @@ public class MovementController : MonoBehaviour ...@@ -180,6 +193,12 @@ public class MovementController : MonoBehaviour
get => m_Grounded; get => m_Grounded;
} }
public float GroundCheckDistance
{
set => m_GroundCheckDistance = value;
get => m_GroundCheckDistance;
}
public void AddJumpCharge(int amount) public void AddJumpCharge(int amount)
{ {
m_TempJumpCount += amount; m_TempJumpCount += amount;
...@@ -205,14 +224,14 @@ public class MovementController : MonoBehaviour ...@@ -205,14 +224,14 @@ public class MovementController : MonoBehaviour
private void OnCollisionEnter2D(Collision2D other) private void OnCollisionEnter2D(Collision2D other)
{ {
if(other.gameObject.layer == m_WhatIsGround) if (other.gameObject.layer == 9)
m_Airborn = false; m_Airborn = false;
} }
private void OnCollisionExit2D(Collision2D other) private void OnCollisionExit2D(Collision2D other)
{ {
if(other.gameObject.layer == m_WhatIsGround) if (other.gameObject.layer == 9)
m_Airborn = true; m_Airborn = true;
} }
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerAnimation : MonoBehaviour
{
public AnimationCurve m_AirScale;
public float m_Time = 10f;
private bool m_isAnimating = false;
private bool m_isScaled = false;
private MovementController r_Controller;
// Start is called before the first frame update
void Start()
{
r_Controller = GetComponent<MovementController>();
}
// Update is called once per frame
void Update()
{
ScalePlayer();
}
public void ScalePlayer()
{
if (Input.GetKeyDown(KeyCode.P) && !m_isAnimating)
{
if (!m_isScaled)
{
StartCoroutine(ScaleUp(m_Time));
}
else
{
StartCoroutine(ScaleDown(m_Time));
}
}
}
private IEnumerator ScaleUp(float t)
{
m_isAnimating = true;
m_isScaled = true;
Vector3 s = transform.localScale;
float step = 1 / t;
for (float i = 0; i <= 1; i += step)
{
float x = m_AirScale.Evaluate(i);
transform.localScale = s + new Vector3(x * Mathf.Sign(s.x), x, x);
r_Controller.GroundCheckDistance += x/2;
yield return new WaitForFixedUpdate();
}
m_isAnimating = false;
}
private IEnumerator ScaleDown(float t)
{
m_isAnimating = true;
m_isScaled = false;
Vector3 s = transform.localScale;
float step = 1 / t;
for (float i = 0; i <= 1; i += step)
{
float x = m_AirScale.Evaluate(i);
transform.localScale = s - new Vector3(x * Mathf.Sign(s.x), x, x);
r_Controller.GroundCheckDistance -= x/2;
yield return new WaitForFixedUpdate();
}
m_isAnimating = false;
}
}
fileFormatVersion: 2
guid: 04143d4b812b542329f18723f680be69
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
...@@ -137,7 +137,7 @@ namespace _Game.Scripts.Player ...@@ -137,7 +137,7 @@ namespace _Game.Scripts.Player
_waterAttack.enabled = false; _waterAttack.enabled = false;
break; break;
} }
_controller.SetMovementParameters(state.GetCurrentMovementState()); //_controller.SetMovementParameters(state.GetCurrentMovementState());
_targetScript.InfuseElement(); _targetScript.InfuseElement();
} }
......
...@@ -8,6 +8,7 @@ namespace _Game.Scripts.Scriptable_Object ...@@ -8,6 +8,7 @@ namespace _Game.Scripts.Scriptable_Object
{ {
[SerializeField] private ElementGameEvent gameEvent; [SerializeField] private ElementGameEvent gameEvent;
[SerializeField] private UnityEvent allResponse;
[SerializeField] private UnityEvent airResponse; [SerializeField] private UnityEvent airResponse;
[SerializeField] private UnityEvent earthResponse; [SerializeField] private UnityEvent earthResponse;
[SerializeField] private UnityEvent fireResponse; [SerializeField] private UnityEvent fireResponse;
...@@ -26,6 +27,7 @@ namespace _Game.Scripts.Scriptable_Object ...@@ -26,6 +27,7 @@ namespace _Game.Scripts.Scriptable_Object
public void OnEventRaised(InfusedElement element) public void OnEventRaised(InfusedElement element)
{ {
allResponse.Invoke();
switch (element) switch (element)
{ {
case InfusedElement.Air: case InfusedElement.Air:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment