Commit a67a3cce authored by Andrew Van Buren's avatar Andrew Van Buren

Added player dash script and physic material 2d.

parent 66003e68
fileFormatVersion: 2
guid: 507f9015dd3807547896c3c9d9e8a4e1
folderAsset: yes
timeCreated: 1486689690
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 120aaee2a73d6364d87bc0095a298b23
timeCreated: 1486689701
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// Sets dash velocity and smoothly decelerates to a minimum velocity
public class Dash : AbstractBehavior {
private float lastDash;
public float coolDown = 1f;
public float dashforce = 5;
public float holdTime = 0.4f;
public float minVelocity = 0.5f;
// Should be called every frame
public void DashCheck() {
// Button pressed, not in cooldown, and not on wall
if (inputState.GetButtonValue(inputButtons[0]) && Time.time > lastDash && !collisionState.onWall) {
StartCoroutine(DoDash());
}
}
// Dash
IEnumerator DoDash() {
// Cooldown
lastDash = Time.time + coolDown;
// Set initial velocity
body.velocity = transform.right * dashforce;
// Disable gravity
float initialGrav = body.gravityScale;
body.gravityScale = 0;
// Decelerate
for (float i = 0; i < holdTime; i += Time.deltaTime) {
// Calculate velocity
Vector2 targetVel = (transform.right * dashforce) * (1 - (i / holdTime));
if(body.velocity.magnitude < minVelocity || collisionState.onWall) {
// Velocity is low enough or collision with wall
Debug.Log("Stopped");
break;
}
// Apply velocity
body.velocity = targetVel;
// Wait
yield return new WaitForEndOfFrame();
}
// Restore gravity
body.gravityScale = initialGrav;
}
}
fileFormatVersion: 2
guid: f246b93f516db6d4881da268c3588e75
timeCreated: 1486687030
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
m_EditorVersion: 5.5.0xf3Linux
m_EditorVersion: 5.5.0f3
\ No newline at end of file
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