Commit dc838b4a authored by Manuel Buß's avatar Manuel Buß
Browse files

Solution A5

parent 00c2b40a
......@@ -13,6 +13,7 @@ GameObject:
- component: {fileID: 3662898596762574005}
- component: {fileID: 5938868358341713651}
- component: {fileID: 4823807144039880843}
- component: {fileID: 8528811166081605641}
m_Layer: 10
m_Name: Player
m_TagString: Untagged
......@@ -108,6 +109,9 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
speed: 5
jumpForce: 7
fallMultiplier: 3
lowJumpMultiplier: 2
--- !u!58 &4823807144039880843
CircleCollider2D:
m_ObjectHideFlags: 0
......@@ -124,3 +128,24 @@ CircleCollider2D:
m_Offset: {x: 0, y: 0}
serializedVersion: 2
m_Radius: 0.365
--- !u!50 &8528811166081605641
Rigidbody2D:
serializedVersion: 4
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1919731297574007180}
m_BodyType: 0
m_Simulated: 1
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
m_Mass: 1
m_LinearDrag: 0
m_AngularDrag: 0.05
m_GravityScale: 1
m_Material: {fileID: 0}
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 1
m_Constraints: 4
......@@ -412,7 +412,7 @@ PrefabInstance:
- target: {fileID: 6411032540897539154, guid: 40c6cd0e710ebc44fa3d278099f9a85c,
type: 3}
propertyPath: m_LocalPosition.y
value: -3.7
value: -3.46
objectReference: {fileID: 0}
- target: {fileID: 6411032540897539154, guid: 40c6cd0e710ebc44fa3d278099f9a85c,
type: 3}
......@@ -469,6 +469,11 @@ PrefabInstance:
propertyPath: player
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5938868358341713651, guid: 40c6cd0e710ebc44fa3d278099f9a85c,
type: 3}
propertyPath: m_Enabled
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 40c6cd0e710ebc44fa3d278099f9a85c, type: 3}
--- !u!1 &1438476478
......@@ -576,7 +581,7 @@ PrefabInstance:
- target: {fileID: 6411032540897539154, guid: 40c6cd0e710ebc44fa3d278099f9a85c,
type: 3}
propertyPath: m_LocalPosition.y
value: -3.7
value: -3.4
objectReference: {fileID: 0}
- target: {fileID: 6411032540897539154, guid: 40c6cd0e710ebc44fa3d278099f9a85c,
type: 3}
......@@ -623,6 +628,11 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5938868358341713651, guid: 40c6cd0e710ebc44fa3d278099f9a85c,
type: 3}
propertyPath: m_Enabled
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 40c6cd0e710ebc44fa3d278099f9a85c, type: 3}
--- !u!1001 &3578180947197286935
......@@ -692,6 +702,11 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 100799371145877907, guid: a1da377d3a985bc4b95e3d994a387f4e,
type: 3}
propertyPath: m_Size.x
value: 20
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: a1da377d3a985bc4b95e3d994a387f4e, type: 3}
--- !u!1001 &5646315729808804356
......
......@@ -2,4 +2,5 @@
{
float Direction();
bool Jump();
bool Jumping();
}
......@@ -16,4 +16,9 @@ public class PlayerInputProvider : MonoBehaviour, IInputProvider
{
return Input.GetButtonDown("Jump" + player);
}
public bool Jumping()
{
return Input.GetButton("Jump" + player);
}
}
......@@ -4,16 +4,47 @@ using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
[SerializeField] private float speed;
[SerializeField] private float speed = 5f;
[SerializeField] private float jumpForce = 2f;
[SerializeField] private float fallMultiplier = 2.5f;
[SerializeField] private float lowJumpMultiplier = 2f;
private IInputProvider input;
private Rigidbody2D rig;
private void Start()
{
input = GetComponent<IInputProvider>();
rig = GetComponent<Rigidbody2D>();
}
private void FixedUpdate()
{
transform.position += Vector3.right * input.Direction() * speed * Time.fixedDeltaTime;
rig.velocity = new Vector2(input.Direction() * speed, rig.velocity.y);
if (input.Jump() && IsGrounded())
{
rig.velocity = new Vector2(rig.velocity.x, jumpForce);
}
//Der Spieler fällt daher wird die Gravitation erhöht um schneller zu fallen
// Da in der Physikberechnug die Gravitation noch angewendet wird muss der Mulitplikator -1 genommen werden
if (rig.velocity.y < 0)
{
rig.velocity += Vector2.up * Physics2D.gravity.y * (fallMultiplier - 1) * Time.fixedDeltaTime;
}
//Falls dir Spieler noch am Springen ist und die Sprungtaste nicht gedrückt hält wird Gravitation erhöt.
//Dadruch springt der Spieler weniger hoch wenn er die Sprungtaste nur kurz drückt
else if (rig.velocity.y > 0 && !input.Jumping())
{
rig.velocity += Vector2.up * Physics2D.gravity.y * (lowJumpMultiplier - 1) * Time.fixedDeltaTime;
}
}
private bool IsGrounded()
{
//Schießt einen Strahl der zurückgibt wenn er was auf dem Layer Ground trifft
RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector2.down, 0.6f, LayerMask.GetMask("Ground"));
return hit.collider != null;
}
}
}
\ No newline at end of file
......@@ -74,7 +74,7 @@ InputManager:
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: w
positiveButton: up
altNegativeButton:
altPositiveButton:
gravity: 1000
......@@ -90,7 +90,7 @@ InputManager:
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: up
positiveButton: w
altNegativeButton:
altPositiveButton:
gravity: 1000
......
......@@ -53,4 +53,4 @@ Physics2DSettings:
m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432}
m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745}
m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804}
m_LayerCollisionMatrix: c8ffffffc8ffffffc8ffffffffffffffc8ffffffc8ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
m_LayerCollisionMatrix: c8f8ffffc8f8ffffc8f8ffffffffffffc8f8ffffc8f8ffffffffffffffffffffc8fcffffc8fcffffc8fbffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
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