Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class player_mvt : MonoBehaviour
- {
- Rigidbody2D rb;
- [Header("Mouvement")]
- public float maxSpeed;
- public float slipperiness;
- [Range(0,1)]
- public float mvtDamp, turnDamp, stopDamp;
- [Space(15)]
- public float jumpTime;
- float _jumpTime;
- [Range(0,1)]
- public float jumpCutMultiplier;
- [Range(1,2)]
- public float fallMultiplier;
- public float maxGravity, baseGravity;
- [Range(0,1)]
- public float flyGravMult;
- public bool flying = false;
- Coroutine flycor;
- [Range(0,1)]
- public float airMvtDamp, airTurnDamp, airStopDamp;
- public bool noFlip;
- [Header("Collisions")]
- public Bounds groundCheck;
- public LayerMask Ground;
- public float mx, my;
- public bool isJump;
- float rota = 0;
- public Bounds platCheck;
- public Bounds platEnd;
- Coroutine dropCor;
- [Space(15)]
- public bool can_move = true;
- float xStore = 0, yStore = 0;
- void Start()
- {
- rb = GetComponent<Rigidbody2D>();
- _jumpTime = jumpTime;
- }
- void FixedUpdate()
- {
- Flip();
- airMove();
- // obsolete
- //Xmove();
- //Fall();
- }
- void airMove()
- {
- if(!can_move) return;
- float xspeed = mx * player_stats.MVT();
- float yspeed = my * player_stats.MVT();
- xStore = velocCalc(ref xStore, xspeed, mx);
- yStore = velocCalc(ref yStore, yspeed, my);
- rb.velocity = (can_move)? new Vector2(xStore, yStore) : rb.velocity;
- }
- float velocCalc(ref float velstore, float veloc, float dir)
- {
- velstore += veloc + dir;
- float stop = Grounded()? stopDamp : airStopDamp;
- float turn = Grounded()? turnDamp : airTurnDamp;
- float damp = Grounded()? mvtDamp : airMvtDamp;
- if (Mathf.Abs(velstore) > player_stats.MVT())
- {
- velstore = player_stats.MVT() * dir;
- }
- if (Mathf.Abs(dir) < 0.01f)
- {
- velstore *= Mathf.Pow(1f - stop, Time.fixedDeltaTime * slipperiness);
- }
- else if (Mathf.Sign(dir) != Mathf.Sign(velstore))
- {
- velstore *= Mathf.Pow(1f - turn, Time.fixedDeltaTime * slipperiness);
- }
- else
- {
- velstore *= Mathf.Pow(1f - damp, Time.fixedDeltaTime * slipperiness);
- }
- return velstore;
- }
- void Flip()
- {
- if(!can_move) return;
- if(noFlip) return;
- if(mx > 0.1f) rota = 0;
- if(mx < -0.1f) rota = 180;
- transform.rotation = Quaternion.Euler(0,rota,0);
- }
- public bool Grounded()
- {
- Collider2D ray = Physics2D.OverlapBox(transform.position + groundCheck.center, groundCheck.extents,0, Ground);
- if(ray != null)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- void OnDrawGizmos()
- {
- Gizmos.color = Color.blue;
- Gizmos.DrawWireCube(transform.position + groundCheck.center, groundCheck.extents);
- Gizmos.color = Color.magenta;
- Gizmos.DrawWireCube(transform.position + platCheck.center, platCheck.extents);
- Gizmos.color = Color.yellow;
- Gizmos.DrawWireCube(transform.position + platEnd.center, platEnd.extents);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment