double jump stuff
This commit is contained in:
@@ -789,6 +789,9 @@ namespace Game
|
||||
private const float stopspeed = 100f;
|
||||
private const float accelerationGround = 12f;
|
||||
private const float jumpVelocity = 270f;
|
||||
private const float jumpBoostTime = 0.5f;
|
||||
private const float jumpBoostVelocity = 100f;
|
||||
private const int jumpBoostMaxJumps = 2;
|
||||
|
||||
private const float maxAirSpeed = 320f;
|
||||
private const float maxAirStrafeSpeed = 30f;
|
||||
@@ -806,6 +809,7 @@ namespace Game
|
||||
|
||||
private bool jumped = false;
|
||||
private float lastJumped = -1f;
|
||||
private int numJumps = 0;
|
||||
private float lastLanded = -1f;
|
||||
|
||||
//private Vector3 safePosition;
|
||||
@@ -850,17 +854,81 @@ namespace Game
|
||||
bool lastGround = onGround;
|
||||
Vector3 lastVelocity = velocity;
|
||||
onGround = true;
|
||||
|
||||
TraceInfo traceGround = CategorizePosition(position, ref velocity);
|
||||
|
||||
bool jumpAction = inputState.jumping;
|
||||
|
||||
if (jumped && !jumpAction)
|
||||
jumped = false; // jump released
|
||||
else if (jumped && Time.GameTime - lastJumped >= autoJumpTime)
|
||||
jumped = false; // jump timeout
|
||||
|
||||
// jump
|
||||
if (onGround && jumpAction && !jumped)
|
||||
{
|
||||
if (OnJump(traceGround, ref velocity))
|
||||
{
|
||||
onGround = false;
|
||||
jumped = true;
|
||||
lastJumped = Time.GameTime;
|
||||
numJumps++;
|
||||
}
|
||||
}
|
||||
|
||||
if (Time.GameTime - lastJumped > jumpBoostTime)
|
||||
numJumps = 0;
|
||||
|
||||
//if (/*onGround && */lastGround != onGround)
|
||||
if (onGround)
|
||||
{
|
||||
// ground friction
|
||||
ApplyFriction(ref velocity);
|
||||
|
||||
// ground acceleration
|
||||
ApplyAcceleration(ref velocity, wishVelocity.Normalized, wishVelocity.Length, float.MaxValue,
|
||||
accelerationGround);
|
||||
}
|
||||
else // air movement
|
||||
{
|
||||
ApplyAirAcceleration(ref velocity, wishVelocity);
|
||||
}
|
||||
|
||||
StepSlideMove(Actor, ref position, ref velocity, onGround);
|
||||
|
||||
|
||||
TraceInfo traceGround2 = CategorizePosition(position, ref velocity);
|
||||
|
||||
rigidBody.Position = position;
|
||||
currentVelocity = velocity;
|
||||
//rigidBody.LinearVelocity = velocity;
|
||||
|
||||
const float landingVelocityThreshold = 120f;
|
||||
const float landingHardVelocityThreshold = 500f;
|
||||
if (currentVelocity.Y - lastVelocity.Y > landingVelocityThreshold)
|
||||
{
|
||||
if (Time.GameTime - lastJumped > 0.01)
|
||||
{
|
||||
bool hardLanding = currentVelocity.Y - lastVelocity.Y > landingHardVelocityThreshold;
|
||||
OnLanded(currentVelocity - lastVelocity, hardLanding);
|
||||
lastLanded = Time.GameTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private TraceInfo CategorizePosition(Vector3 position, ref Vector3 velocity)
|
||||
{
|
||||
Vector3 groundDelta = Gravity.Normalized;//Gravity.Normalized * (collisionMargin * 2);
|
||||
//if (velocity.Y < 0f)
|
||||
// groundDelta = Gravity.Normalized * velocity.Y * Time.DeltaTime;
|
||||
TraceInfo traceGround = TracePlayer(Actor, position, position + groundDelta);
|
||||
//Console.PrintDebug(1, true, "startSolid: " + traceGround.startSolid);
|
||||
|
||||
if (!traceGround.startSolid && traceGround.fraction < 1f &&
|
||||
-Vector3.Dot(Gravity.Normalized, traceGround.hitNormal) < slopeNormal)
|
||||
{
|
||||
//Console.Print("slope?");
|
||||
// slope
|
||||
// clip velocity
|
||||
|
||||
Vector3 bounce = groundDelta;
|
||||
//Vector3 velocityProjected = Vector3.ProjectOnPlane(velocity, normal);
|
||||
float backoff = Vector3.Dot(bounce, traceGround.hitNormal) * 2f;
|
||||
@@ -891,70 +959,38 @@ namespace Game
|
||||
//Console.PrintDebug(1, true, "issolid? :" + traceGround.startSolid);
|
||||
}
|
||||
|
||||
// TODO: snap to ground here
|
||||
//if (onGround && !slope)
|
||||
// velocity.Y = 0f;
|
||||
|
||||
bool jumpAction = inputState.jumping;
|
||||
|
||||
if (jumped && !jumpAction)
|
||||
jumped = false; // jump released
|
||||
else if (jumped && Time.GameTime - lastJumped >= autoJumpTime)
|
||||
jumped = false; // jump timeout
|
||||
|
||||
// jump
|
||||
if (onGround && jumpAction && !jumped)
|
||||
{
|
||||
if (OnJump(traceGround, ref velocity))
|
||||
{
|
||||
onGround = false;
|
||||
jumped = true;
|
||||
lastJumped = Time.GameTime;
|
||||
}
|
||||
}
|
||||
|
||||
//if (/*onGround && */lastGround != onGround)
|
||||
if (onGround)
|
||||
{
|
||||
// ground friction
|
||||
ApplyFriction(ref velocity);
|
||||
|
||||
// ground acceleration
|
||||
ApplyAcceleration(ref velocity, wishVelocity.Normalized, wishVelocity.Length, float.MaxValue,
|
||||
accelerationGround);
|
||||
}
|
||||
else // air movement
|
||||
{
|
||||
ApplyAirAcceleration(ref velocity, wishVelocity);
|
||||
}
|
||||
|
||||
StepSlideMove(Actor, ref position, ref velocity, onGround);
|
||||
|
||||
rigidBody.Position = position;
|
||||
currentVelocity = velocity;
|
||||
//rigidBody.LinearVelocity = velocity;
|
||||
|
||||
const float landingVelocityThreshold = 120f;
|
||||
const float landingHardVelocityThreshold = 500f;
|
||||
if (currentVelocity.Y - lastVelocity.Y > landingVelocityThreshold)
|
||||
{
|
||||
if (Time.GameTime - lastJumped > 0.01)
|
||||
{
|
||||
bool hardLanding = currentVelocity.Y - lastVelocity.Y > landingHardVelocityThreshold;
|
||||
OnLanded(currentVelocity - lastVelocity, hardLanding);
|
||||
lastLanded = Time.GameTime;
|
||||
}
|
||||
}
|
||||
// TODO: snap to ground here?
|
||||
return traceGround;
|
||||
}
|
||||
|
||||
private bool OnJump(TraceInfo traceGround, ref Vector3 velocity)
|
||||
{
|
||||
float jumpVel = jumpVelocity;
|
||||
if (Time.GameTime - lastJumped < jumpBoostTime)
|
||||
jumpVel += jumpBoostVelocity;
|
||||
|
||||
// reset velocity from gravity
|
||||
if (-Vector3.Dot(Gravity.Normalized, velocity) < 0 &&
|
||||
Vector3.Dot(velocity, traceGround.hitNormal) < -0.1)
|
||||
{
|
||||
Console.Print("vel before: " + velocity.Y);
|
||||
velocity = Vector3.ProjectOnPlane(velocity, traceGround.hitNormal);
|
||||
Console.Print("vel after: " + velocity.Y);
|
||||
}
|
||||
|
||||
velocity += Vector3.Up * jumpVelocity;
|
||||
velocity += Vector3.Up * jumpVel;
|
||||
|
||||
bool ktjump = true;
|
||||
if (ktjump)
|
||||
{
|
||||
if (velocity.Y < jumpVel)
|
||||
velocity.Y = jumpVel;
|
||||
}
|
||||
|
||||
Console.Print("jumpvel: " + velocity.Y);
|
||||
|
||||
if (!predicting)
|
||||
{
|
||||
|
||||
@@ -40,6 +40,8 @@ namespace Game
|
||||
public string mapPath = @"C:\dev\Goake\maps\aerowalk\aerowalk.map";
|
||||
//private string mapPath = @"C:\dev\GoakeFlax\Assets\Maps\problematic.map";
|
||||
|
||||
public bool importLights = false;
|
||||
|
||||
Model model;
|
||||
private MaterialBase missingMaterial;
|
||||
|
||||
@@ -300,7 +302,7 @@ namespace Game
|
||||
{
|
||||
worldSpawnActor = Actor.AddChild<Actor>();
|
||||
worldSpawnActor.Name = "WorldSpawn";
|
||||
//worldSpawnActor.HideFlags |= HideFlags.DontSave;
|
||||
worldSpawnActor.HideFlags |= HideFlags.DontSave;
|
||||
worldSpawnActor.HideFlags |= HideFlags.DontSelect;
|
||||
}
|
||||
|
||||
@@ -683,6 +685,7 @@ namespace Game
|
||||
}
|
||||
|
||||
// Handle entities
|
||||
if (importLights)
|
||||
{
|
||||
sw.Restart();
|
||||
int lightIndex = 0;
|
||||
@@ -696,11 +699,11 @@ namespace Game
|
||||
return new Vector3(float.Parse(points[0]), float.Parse(points[2]), float.Parse(points[1]));
|
||||
}
|
||||
|
||||
Color ParseColor(string origin)
|
||||
/*Color ParseColor(string origin)
|
||||
{
|
||||
string[] points = origin.Split(new char[] { ' ' });
|
||||
return new Color(float.Parse(points[0]), float.Parse(points[1]), float.Parse(points[2]));
|
||||
}
|
||||
}*/
|
||||
|
||||
//Console.Print("light");
|
||||
PointLight light = worldSpawnActor.AddChild<PointLight>();
|
||||
@@ -742,7 +745,7 @@ namespace Game
|
||||
lightIndex++;
|
||||
}
|
||||
|
||||
Console.Print("test: " + (new Vector2(1f,0f) == Vector2.Zero));
|
||||
//Console.Print("test: " + (new Vector2(1f,0f) == Vector2.Zero));
|
||||
|
||||
Console.Print("light parsing time: " + sw.Elapsed.TotalMilliseconds + "ms");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user