@@ -13,23 +13,16 @@ public enum States

public States state;

public float speed;
public float maxVelocity;
[Range(0, 1)]
public float drag;
public float jumpForce;
public float wallJumpForce;
public float wallJumpSidewaysForce;
public float wallSlideSpeed;

public float dashVelocity;
public float speed = 14f;
public float jumpForce = 14f;
public float accel = 6f;
public float airAccel = 3f;

public float dashVelocity;
public float dashCooldown;
public float dashTimeStamp;

public float stunTime;

public bool grounded = false;
public bool onWall = false;
public bool canMove = true;

Rigidbody2D rb;
@@ -43,6 +36,7 @@ public enum States
float h;

private GroundState groundState;
private Vector3 input; // z is dash

void Start ()
{
@@ -53,199 +47,99 @@ void Start ()
groundState = new GroundState(transform.gameObject);
}

void FixedUpdate ()
void Update ()
{
h = Input.GetAxis("Horizontal");

if (canMove)
{
Movement();
Dash();
}
}
input.x = Input.GetAxis("Horizontal");


void Dash()
{
switch (state)
{
case States.Ready:

if (Input.GetButtonDown("X") && h != 0)
{
state = States.Dashing;
}
break;

case States.Dashing:

StartCoroutine(PlayerDash());
dashTimeStamp = Time.time + dashCooldown;
state = States.Cooldown;
break;

case States.Cooldown:

if (dashTimeStamp <= Time.time)
{
state = States.Ready;
}
break;
}
}
if (Input.GetButton("A"))
input.y = 1;

IEnumerator PlayerDash()
{
trail.time = 1f;
if(Input.GetButtonDown("X"))
{
input.z = 1;
}
}

rb.velocity = new Vector2(dashVelocity * h, 0);
rb.gravityScale = 0;
yield return new WaitForSeconds(0.1f);
rb.velocity = Vector2.zero;
rb.velocity = new Vector2(maxVelocity * h, 0);
rb.gravityScale = 1;

trail.time = .1f;
}

IEnumerator Stun()
void FixedUpdate()
{
canMove = false;
rb.velocity = new Vector2(0, rb.velocity.y);
yield return new WaitForSeconds(stunTime);
canMove = true;
}

void Movement()
{
//Player Movement
currentVelocity = rb.velocity;

//MaxVelocity Settings
if (currentVelocity.x >= maxVelocity)
{
currentVelocity.x = maxVelocity;
}
if (currentVelocity.x <= -maxVelocity)
{
currentVelocity.x = -maxVelocity;
}
if (currentVelocity.y <= -10)
{
currentVelocity.y = 10;
}

if (Input.GetAxis("Horizontal") != 0)
{
rb.AddForce(new Vector2(h * speed, 0));
}
else
{
rb.velocity = new Vector2(rb.velocity.x * drag, rb.velocity.y);
}
Dash();

//Jumping/Falling
if (Input.GetButton("A") && groundState.isGround() && !groundState.isWall())
{
rb.velocity = new Vector2(rb.velocity.x, jumpForce);
}
if (rb.velocity.y < 0 && !groundState.isWall())
{
rb.velocity += Vector2.up * Physics2D.gravity.y * (fallingGrav) * Time.deltaTime;
}
else if (rb.velocity.y > 0 && !Input.GetButton("A") && !groundState.isWall())
{
rb.velocity += Vector2.up * Physics2D.gravity.y * (lowJumpMulitplier) * Time.deltaTime;
}


//RaycastHit2D leftRay = Physics2D.Raycast(transform.position, Vector2.left);
//RaycastHit2D rightRay = Physics2D.Raycast(transform.position, Vector2.right);
rb.AddForce(new Vector2(((input.x * speed) - rb.velocity.x) * (groundState.isGround() ? accel : airAccel), 0)); //Move player.
rb.velocity = new Vector2((input.x == 0 && groundState.isGround()) ? 0 : rb.velocity.x,
(input.y == 1 && groundState.isTouching()) ? jumpForce : rb.velocity.y); //Stop player if input.x is 0 (and grounded) and jump if input.y is 1

//if (leftRay.collider != null && rightRay.collider != null)
//{
// float distanceLeft = Mathf.Abs(leftRay.point.x - transform.position.x);
// float distanceRight = Mathf.Abs(rightRay.point.x - transform.position.x);
if (groundState.isWall() && !groundState.isGround() && input.y == 1)
rb.velocity = new Vector2(-groundState.wallDirection() * speed * 0.75f, rb.velocity.y); //Add force negative to wall direction (with speed reduction)

// if (distanceLeft < distanceRight)
// {

// }
// else if (distanceLeft > distanceRight)
// {
// wallJumpSidewaysForce *= -1;
// }
//}

//WallJump
if (Input.GetButton("A") && !groundState.isGround() && groundState.isWall())
{
onWall = false;

//RaycastHit2D leftRay = Physics2D.Raycast(transform.position, Vector2.left);
//RaycastHit2D rightRay = Physics2D.Raycast(transform.position, Vector2.right);

//if (leftRay.collider != null && rightRay.collider != null)
//{
// float distanceLeft = Mathf.Abs(leftRay.point.x - transform.position.x);
// float distanceRight = Mathf.Abs(rightRay.point.x - transform.position.x);

// if (distanceLeft < distanceRight)
// {

// }
// else if (distanceLeft > distanceRight)
// {
// wallJumpSidewaysForce *= -1;
// }
//}
rb.velocity = new Vector2(groundState.wallDirection() * -wallJumpSidewaysForce, wallJumpForce);
//rb.AddForce(new Vector2(wallJumpSidewaysForce, wallJumpForce));
}
}
input.y = 0;
}

private void OnCollisionEnter2D(Collision2D collision)
{
//Collider2D coll = collision.collider;

//if (collision.gameObject.CompareTag("Ground"))
//{
// grounded = true;
// onWall = false;
//}
//if (collision.gameObject.CompareTag("Wall"))
//{
// if (!grounded)
// {
// Vector2 contactPoint = collision.contacts[0].point;
// Vector2 center = coll.bounds.center;
// if (contactPoint.x > center.x)
// {
// wallJumpSidewaysForce = -20f;
// }
// else if (contactPoint.x < center.x)
// {
// wallJumpSidewaysForce = 20f;
// }
// onWall = true;
// }
//}

if (collision.gameObject.CompareTag("Mine"))
{
StartCoroutine(Stun());
Destroy(collision.gameObject);
}
}

private void OnCollisionExit2D(Collision2D collision)
{
//if (collision.gameObject.CompareTag("Wall"))
//{
// onWall = false;
//}
}
void Dash()
{
switch (state)
{
case States.Ready:

if (input.z == 1 && input.x != 0)
{
state = States.Dashing;
}
break;

case States.Dashing:

StartCoroutine(PlayerDash());
dashTimeStamp = Time.time + dashCooldown;
state = States.Cooldown;
break;

case States.Cooldown:

if (dashTimeStamp <= Time.time)
{
state = States.Ready;
}
break;
}
input.z = 0;
}

IEnumerator PlayerDash()
{
trail.time = 1f;

rb.velocity = new Vector2(dashVelocity * input.x, 0);
rb.gravityScale = 0;
yield return new WaitForSeconds(0.1f);
rb.velocity = Vector2.zero;
rb.velocity = new Vector2(speed * input.x, 0);
rb.gravityScale = 3;

trail.time = .1f;
}

IEnumerator Stun()
{
canMove = false;
rb.velocity = new Vector2(0, rb.velocity.y);
yield return new WaitForSeconds(stunTime);
canMove = true;
}


private void OnTriggerEnter2D(Collider2D collision)
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.CompareTag("SlowField"))
{
@@ -249,206 +249,6 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &852135606 stripped
GameObject:
m_PrefabParentObject: {fileID: 1063145410450130, guid: e6a3e106cf1cc7f4395b07c4b60ed00e,
type: 2}
m_PrefabInternal: {fileID: 1384030207}
--- !u!96 &852135612
TrailRenderer:
serializedVersion: 2
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 852135606}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 0
m_ReflectionProbeUsage: 0
m_Materials:
- {fileID: 2100000, guid: 064e560597154d64784b86eb49bc500f, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_Time: 0.1
m_Parameters:
serializedVersion: 2
widthMultiplier: 1
widthCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 2
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 0
colorGradient:
serializedVersion: 2
key0: {r: 1, g: 1, b: 1, a: 0.39215687}
key1: {r: 1, g: 1, b: 1, a: 0}
key2: {r: 0, g: 0, b: 0, a: 0}
key3: {r: 0, g: 0, b: 0, a: 0}
key4: {r: 0, g: 0, b: 0, a: 0}
key5: {r: 0, g: 0, b: 0, a: 0}
key6: {r: 0, g: 0, b: 0, a: 0}
key7: {r: 0, g: 0, b: 0, a: 0}
ctime0: 0
ctime1: 65535
ctime2: 0
ctime3: 0
ctime4: 0
ctime5: 0
ctime6: 0
ctime7: 0
atime0: 0
atime1: 65535
atime2: 0
atime3: 0
atime4: 0
atime5: 0
atime6: 0
atime7: 0
m_Mode: 0
m_NumColorKeys: 2
m_NumAlphaKeys: 2
numCornerVertices: 0
numCapVertices: 0
alignment: 0
textureMode: 0
generateLightingData: 0
m_MinVertexDistance: 0.1
m_Autodestruct: 0
--- !u!1 &1110916359
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 1313248580827242, guid: 89ca92d48eb40b241b0ebbdf015eedda,
type: 2}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 1110916360}
- component: {fileID: 1110916362}
- component: {fileID: 1110916361}
m_Layer: 0
m_Name: LeftWall (2)
m_TagString: Wall
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1110916360
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 4243128247168204, guid: 89ca92d48eb40b241b0ebbdf015eedda,
type: 2}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1110916359}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -2.33, y: 0, z: 0}
m_LocalScale: {x: 1, y: 20, z: 1}
m_Children: []
m_Father: {fileID: 1225592665}
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!61 &1110916361
BoxCollider2D:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 61290333035368016, guid: 89ca92d48eb40b241b0ebbdf015eedda,
type: 2}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1110916359}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 6200000, guid: b4dcedfb18224f64e8f7fd97f2508441, type: 2}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0.5, y: 0.5}
oldSize: {x: 1, y: 1}
newSize: {x: 1, y: 1}
adaptiveTilingThreshold: 0.5
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 1, y: 1}
m_EdgeRadius: 0
--- !u!212 &1110916362
SpriteRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 212195108363740240, guid: 89ca92d48eb40b241b0ebbdf015eedda,
type: 2}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1110916359}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_Materials:
- {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_Sprite: {fileID: 21300000, guid: 08f20c3c247304a40912066186db1c70, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 1, y: 1}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
--- !u!4 &1225592665 stripped
Transform:
m_PrefabParentObject: {fileID: 4400711787747824, guid: 89ca92d48eb40b241b0ebbdf015eedda,
type: 2}
m_PrefabInternal: {fileID: 137982146}
--- !u!1001 &1384030207
Prefab:
m_ObjectHideFlags: 0
@@ -488,154 +288,21 @@ Prefab:
propertyPath: m_RootOrder
value: 2
objectReference: {fileID: 0}
- target: {fileID: 114069902457986338, guid: e6a3e106cf1cc7f4395b07c4b60ed00e,
type: 2}
propertyPath: speed
value: 100
objectReference: {fileID: 0}
- target: {fileID: 50421309916970988, guid: e6a3e106cf1cc7f4395b07c4b60ed00e,
type: 2}
propertyPath: m_LinearDrag
value: 0
objectReference: {fileID: 0}
- target: {fileID: 114069902457986338, guid: e6a3e106cf1cc7f4395b07c4b60ed00e,
- target: {fileID: 61177386872692960, guid: e6a3e106cf1cc7f4395b07c4b60ed00e,
type: 2}
propertyPath: dashCooldown
value: 1
objectReference: {fileID: 0}
- target: {fileID: 114069902457986338, guid: e6a3e106cf1cc7f4395b07c4b60ed00e,
type: 2}
propertyPath: dashVelocity
value: 50
objectReference: {fileID: 0}
- target: {fileID: 114069902457986338, guid: e6a3e106cf1cc7f4395b07c4b60ed00e,
type: 2}
propertyPath: drag
value: 0.7
objectReference: {fileID: 0}
- target: {fileID: 114069902457986338, guid: e6a3e106cf1cc7f4395b07c4b60ed00e,
type: 2}
propertyPath: stunTime
value: 1
objectReference: {fileID: 0}
- target: {fileID: 114069902457986338, guid: e6a3e106cf1cc7f4395b07c4b60ed00e,
type: 2}
propertyPath: afterImage
propertyPath: m_Material
value:
objectReference: {fileID: 0}
- target: {fileID: 114069902457986338, guid: e6a3e106cf1cc7f4395b07c4b60ed00e,
objectReference: {fileID: 6200000, guid: db3b38c15c27d8249b4ee18122ef949a, type: 2}
- target: {fileID: 50421309916970988, guid: e6a3e106cf1cc7f4395b07c4b60ed00e,
type: 2}
propertyPath: wallJumpSidewaysForce
value: 20
propertyPath: m_GravityScale
value: 2
objectReference: {fileID: 0}
- target: {fileID: 114069902457986338, guid: e6a3e106cf1cc7f4395b07c4b60ed00e,
type: 2}
propertyPath: wallJumpForce
value: 7
propertyPath: jumpForce
value: 14
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: e6a3e106cf1cc7f4395b07c4b60ed00e, type: 2}
m_IsPrefabParent: 0
--- !u!1 &1525807990
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 1313248580827242, guid: 89ca92d48eb40b241b0ebbdf015eedda,
type: 2}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 1525807991}
- component: {fileID: 1525807993}
- component: {fileID: 1525807992}
m_Layer: 0
m_Name: LeftWall (1)
m_TagString: Wall
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1525807991
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 4243128247168204, guid: 89ca92d48eb40b241b0ebbdf015eedda,
type: 2}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1525807990}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 4.02, y: 0, z: 0}
m_LocalScale: {x: 1, y: 20, z: 1}
m_Children: []
m_Father: {fileID: 1225592665}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!61 &1525807992
BoxCollider2D:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 61290333035368016, guid: 89ca92d48eb40b241b0ebbdf015eedda,
type: 2}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1525807990}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 6200000, guid: b4dcedfb18224f64e8f7fd97f2508441, type: 2}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0.5, y: 0.5}
oldSize: {x: 1, y: 1}
newSize: {x: 1, y: 1}
adaptiveTilingThreshold: 0.5
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 1, y: 1}
m_EdgeRadius: 0
--- !u!212 &1525807993
SpriteRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 212195108363740240, guid: 89ca92d48eb40b241b0ebbdf015eedda,
type: 2}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1525807990}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_Materials:
- {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_Sprite: {fileID: 21300000, guid: 08f20c3c247304a40912066186db1c70, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 1, y: 1}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0