Refined Movement and added Jump

main
thoopchuk26 4 years ago
parent 51ef396fa9
commit 42c99a3027

@ -267,10 +267,11 @@ MonoBehaviour:
_Velocity: 0
_MaxVelocity: 6
_Acc: 0
_AccSpeed: 0.2
_AccSpeed: 0.25
_MaxAcc: 2
_MinAcc: -2
_Deceleration: 0.5
_Deceleration: 0.4
jumpForce: 350
--- !u!50 &1000257560
Rigidbody2D:
serializedVersion: 4

@ -16,10 +16,11 @@ public class movement : MonoBehaviour
public float _MaxAcc = 1.0f;
public float _MinAcc = -1.0f;
public float _Deceleration = 2f;
public float jumpForce = 350;
// Start is called before the first frame update
void Start()
{
rb2d = GetComponent<Rigidbody2D>();
}
@ -62,6 +63,13 @@ public class movement : MonoBehaviour
}
rb2d.velocity = new Vector2(_Velocity, rb2d.velocity.y);
if (Input.GetKeyDown("space") && !jumping)
{
rb2d.velocity = new Vector2(rb2d.velocity.x, 0);
rb2d.AddForce(new Vector2(0, jumpForce));
jumping = true;
}
}
private void acceleration()
@ -90,7 +98,7 @@ public class movement : MonoBehaviour
{
_Velocity += _Deceleration;
}
if (_Velocity < 0.001 && _Velocity > -0.001)
if (_Velocity < _Deceleration && _Velocity > -_Deceleration)
{
_Velocity = 0;
}
@ -103,4 +111,9 @@ public class movement : MonoBehaviour
scaler.x *= -1;
transform.localScale = scaler;
}
private void OnCollisionEnter2D(Collision2D collision)
{
jumping = false;
}
}

Loading…
Cancel
Save