Commit 5e80266d authored by Sebastian Frey's avatar Sebastian Frey

Merge remote-tracking branch 'origin/master'

parents 4b786555 d8b09187
......@@ -13,7 +13,7 @@ MonoBehaviour:
m_Name: Movement States
m_EditorClassIdentifier: Assembly-CSharp:_Game.Scripts.Scriptable_Object:MovementStates
airMoveState:
jumpForce: 5
jumpForce: 10
smoothing: 0.03
airControl: 1
canSwim: 1
......
......@@ -12,7 +12,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 353b156b7c59b1c45a8767d7500b31fb, type: 3}
m_Name: PlayerState
m_EditorClassIdentifier:
currentInfusedElement: 2
currentInfusedElement: 0
currentMoveState:
jumpForce: 10
smoothing: 0.03
......
......@@ -5,11 +5,11 @@ using UnityEngine;
[RequireComponent(typeof(MovementController))]
public class InputController : MonoBehaviour {
private MovementController m_Controller;
private MovementController m_Controller;
private float m_XAxis, m_YAxis;
private bool m_Jump = false;
void Start () {
void Start () {
//Sucht nach MovementController auf dem selben Gameobject
m_Controller = GetComponent<MovementController>();
}
......@@ -24,4 +24,4 @@ public class InputController : MonoBehaviour {
//Ruft Move Methode im MovementController auf dient der Bewegung des Charakters
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
[SerializeField] private bool m_AirControl = false; // Whether or not a player can steer while jumping;
[SerializeField] private bool m_CanSwim = true;
[Header("Ground Check Control")]
[SerializeField] private LayerMask m_WhatIsGround; // A mask determining what is ground to the character
[Header("Ground Check Control")] [SerializeField]
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 float m_GroundCheckDistance = 1.5f;
[SerializeField] private float m_GroundedRadius = .2f;
......@@ -47,19 +48,6 @@ public class MovementController : MonoBehaviour
public UnityEvent OnSwimEvent;
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()
{
m_Rigidbody2D = GetComponent<Rigidbody2D>();
......@@ -96,7 +84,15 @@ public class MovementController : MonoBehaviour
if (m_RaycastHits2D[i].transform.gameObject == gameObject) continue;
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;
if (!wasGrounded)
{
......@@ -106,7 +102,6 @@ public class MovementController : MonoBehaviour
}
public void Move(Vector2 move, bool jump)
{
//only control the player if grounded or airControl is turned on
......@@ -136,12 +131,18 @@ public class MovementController : MonoBehaviour
// If the player should 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_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;
OnJumpEvent.Invoke();
StartCoroutine(Wait(m_SecondsWaitToJump));
......@@ -152,10 +153,23 @@ public class MovementController : MonoBehaviour
{
m_Rigidbody2D.velocity += Vector2.up * Physics2D.gravity.y * (m_fallMultiplier - 1) * Time.deltaTime;
}
//else if (m_Rigidbody2D.velocity.y > 0 && !Input.GetButton("Jump"))
//{
// m_Rigidbody2D.velocity += Vector2.up * Physics2D.gravity.y * (m_lowJumpMultiplier - 1) * Time.deltaTime;
//}
else if (m_Rigidbody2D.velocity.y > 0 && !Input.GetButton("Jump"))
{
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)
......@@ -178,6 +192,12 @@ public class MovementController : MonoBehaviour
get => m_Grounded;
}
public float GroundCheckDistance
{
set => m_GroundCheckDistance = value;
get => m_GroundCheckDistance;
}
public void AddJumpCharge(int amount)
{
m_TempJumpCount += amount;
......@@ -203,14 +223,14 @@ public class MovementController : MonoBehaviour
private void OnCollisionEnter2D(Collision2D other)
{
if(other.gameObject.layer == m_WhatIsGround)
m_Airborn = false;
if (other.gameObject.layer == 9)
m_Airborn = false;
}
private void OnCollisionExit2D(Collision2D other)
{
if(other.gameObject.layer == m_WhatIsGround)
m_Airborn = true;
if (other.gameObject.layer == 9)
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:
......@@ -134,7 +134,7 @@ namespace _Game.Scripts.Player
_waterAttack.enabled = true;
break;
}
_controller.SetMovementParameters(state.GetCurrentMovementState());
//_controller.SetMovementParameters(state.GetCurrentMovementState());
_targetScript.InfuseElement();
}
......
......@@ -8,6 +8,7 @@ namespace _Game.Scripts.Scriptable_Object
{
[SerializeField] private ElementGameEvent gameEvent;
[SerializeField] private UnityEvent allResponse;
[SerializeField] private UnityEvent airResponse;
[SerializeField] private UnityEvent earthResponse;
[SerializeField] private UnityEvent fireResponse;
......@@ -26,6 +27,7 @@ namespace _Game.Scripts.Scriptable_Object
public void OnEventRaised(InfusedElement element)
{
allResponse.Invoke();
switch (element)
{
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