Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
Birb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gadig
Birb
Commits
61a84506
Commit
61a84506
authored
Apr 06, 2017
by
Conner Stern
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
made dash use animationcurve
parent
24be4a20
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
15 deletions
+69
-15
Assets/Scripts/Birb/Dash.cs
Assets/Scripts/Birb/Dash.cs
+66
-15
Assets/Scripts/Birb/Jump.cs
Assets/Scripts/Birb/Jump.cs
+3
-0
No files found.
Assets/Scripts/Birb/Dash.cs
View file @
61a84506
...
...
@@ -7,10 +7,21 @@ using UnityEngine;
public
class
Dash
:
AbstractBehavior
{
//The velocity curve over time
[
SerializeField
]
private
AnimationCurve
dashVelocityCurve
;
private
float
distRatio
{
get
{
return
dashVelocityCurve
.
keys
[
dashVelocityCurve
.
length
-
1
].
time
/
dashDistance
;}
}
private
float
distMultiplier
=
1
;
//The time of the dash
//[SerializeField] private float dashTime;
//Distance to dash
[
SerializeField
]
private
float
dashDistance
;
Jump
jumpScript
;
public
float
coolDown
=
1f
;
public
float
dashforce
=
5
;
public
float
holdTime
=
0.4f
;
public
float
minVelocity
=
0.5f
;
private
bool
_isDashing
=
false
;
private
Transform
dashMeter
;
...
...
@@ -19,6 +30,8 @@ public class Dash : AbstractBehavior {
private
Walk
walk
;
private
bool
jumpDuringDash
=
false
;
// Call to check if currently dashing
public
bool
isDashing
{
...
...
@@ -30,9 +43,30 @@ public class Dash : AbstractBehavior {
}
void
Start
()
{
jumpScript
=
GetComponent
<
Jump
>();
dashMeter
=
GameObject
.
FindGameObjectWithTag
(
"DashMeter"
).
transform
;
coll
=
GetComponent
<
CircleCollider2D
>();
walk
=
GetComponent
<
Walk
>();
distMultiplier
=
ApproximateSpeedMultiplier
(
dashVelocityCurve
,
100
);
//Setting up the v0 and a with Kenimatic Equations (Deprecated)
//dashVelocity = CalculateDashVelocity(dashDistance, dashTime, finalVelocity);
//dashDeceleration = CalculateDashDeceleration(finalVelocity, dashTime, dashVelocity);
}
float
ApproximateSpeedMultiplier
(
AnimationCurve
velocityOverTime
,
int
samples
){
float
time
=
velocityOverTime
.
Evaluate
(
velocityOverTime
.
keys
[
dashVelocityCurve
.
length
-
1
].
time
);
float
distTraveled
=
0
;
for
(
float
i
=
0
;
i
<
time
;
i
+=
time
/
samples
){
distTraveled
+=
velocityOverTime
.
Evaluate
(
i
);
}
distTraveled
/=
samples
;
return
(
dashDistance
/
distTraveled
);
}
void
Update
()
{
...
...
@@ -41,6 +75,10 @@ public class Dash : AbstractBehavior {
}
UpdateUI
();
animator
.
SetBool
(
"is dashing"
,
isDashing
);
if
(
jumpScript
.
_jumpRequested
&&
isDashing
){
print
(
"jumped"
);
jumpDuringDash
=
true
;
}
}
// Should be called every frame
...
...
@@ -63,35 +101,37 @@ public class Dash : AbstractBehavior {
if
(
walk
!=
null
)
{
walk
.
enabled
=
false
;
}
//stores distance remaining in dash
float
distRemaining
=
dashDistance
;
// dash direction vector
Vector2
dir
=
((
int
)
direction
)
*
Vector2
.
right
;
// Cooldown
lastDash
=
Time
.
time
+
coolDown
;
// Is dashing
isDashing
=
true
;
// Set initial velocity
body
.
velocity
=
dir
*
dashforce
;
// Disable gravity
float
initialGrav
=
body
.
gravityScale
;
body
.
gravityScale
=
0
;
// results for circle cast
RaycastHit2D
[]
results
=
new
RaycastHit2D
[
8
];
// Decelerate
for
(
float
i
=
0
;
i
<
holdTime
;
i
+=
Time
.
deltaTime
)
{
//
Calculate
velocity
Vector2
targetVel
=
(
dir
*
dashforce
)
*
(
1
-
(
i
/
holdTime
));
if
(
body
.
velocity
.
magnitude
<
minVelocity
||
collisionState
.
onWall
)
{
while
(
distRemaining
>=
0
)
{
//
Set initial
velocity
float
currentVel
=
dashVelocityCurve
.
Evaluate
(
distRatio
*
(
dashDistance
-
distRemaining
));
//check if we need to stop dashing
if
(
distRemaining
<=
0
||
collisionState
.
onWall
||
jumpDuringDash
)
{
// Velocity is low enough or collision with wall
jumpDuringDash
=
false
;
print
(
"ended dash"
);
break
;
}
// Apply velocity
body
.
velocity
=
targetVel
;
body
.
velocity
=
currentVel
*
dir
;
print
(
body
.
velocity
);
// Apply dist remaining reduciton
distRemaining
-=
currentVel
*
Time
.
deltaTime
;
float
checkDistance
=
body
.
velocity
.
magnitude
*
Time
.
deltaTime
;
...
...
@@ -104,7 +144,7 @@ public class Dash : AbstractBehavior {
breakable
.
Break
();
}
}
// Wait
yield
return
new
WaitForEndOfFrame
();
}
...
...
@@ -118,7 +158,18 @@ public class Dash : AbstractBehavior {
// Is not dashing
isDashing
=
false
;
}
/*
private float CalculateDashVelocity(float dashDist, float dashtTime, float finalVel){
//manipulated equation "d = .5 * (v + v0) * t" to get v by itself
float velocity = 2 * (dashDist / dashTime) - finalVel;
return velocity;
}
*/
private
float
CalculateDashDeceleration
(
float
finalVel
,
float
dashTime
,
float
startVel
){
//manipulated equation v = v0 + at to get a by itself
float
acceleration
=
(
finalVel
-
startVel
)
/
dashTime
;
return
acceleration
;
}
public
void
ActivateIgnoringCooldown
(
Directions
direction
)
{
StartCoroutine
(
DashRoutine
(
direction
));
}
...
...
Assets/Scripts/Birb/Jump.cs
View file @
61a84506
...
...
@@ -10,6 +10,9 @@ public class Jump : AbstractBehavior {
public
float
wallJumpHeight
=
3
;
public
float
wallJumpHorizontalSpeed
=
5
;
public
bool
_jumpRequested
{
get
{
return
jumpRequested
;}
}
bool
jumpRequested
;
int
airJumpsMade
=
0
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment