double jump stuff

This commit is contained in:
2022-04-30 16:12:23 +03:00
parent cbb2d530cb
commit 10ff8132cb
11 changed files with 143 additions and 62 deletions

View File

@@ -11,7 +11,7 @@
"Transform": {
"Translation": {
"X": 73.19660949707031,
"Y": 0.0,
"Y": -33.01502227783203,
"Z": -139.43125915527345
},
"Orientation": {
@@ -56,6 +56,12 @@
"ParentID": "51c770f24232abbb112cc98b296820d8",
"V": {}
},
{
"ID": "1b648b37406d810fecb8e1ba45a51c84",
"TypeName": "Game.CameraSpring",
"ParentID": "51c770f24232abbb112cc98b296820d8",
"V": {}
},
{
"ID": "eb46ab96465957dc67a052bd0e2ad1e5",
"TypeName": "FlaxEngine.Camera",
@@ -245,6 +251,30 @@
},
"StaticFlags": 0,
"CollisionData": "593d92914c4bd54679ddec9e539bba80"
},
{
"ID": "12cd95b64f5145dcae7b28b7404ef512",
"TypeName": "FlaxEngine.StaticModel",
"ParentID": "a50f3639419a8306036ecfab7115e772",
"Name": "PlayerModel",
"Transform": {
"Scale": {
"X": 0.30000001192092898,
"Y": 0.5600000023841858,
"Z": 0.30000001192092898
}
},
"Model": "b43f0f8f4aaba3f3156896a5a22ba493",
"Buffer": {
"Entries": [
{
"Material": "a75d425f40ef7ba5df0fdb8d470e8a78",
"ShadowsMode": 3,
"Visible": true,
"ReceiveDecals": true
}
]
}
}
]
}

View File

@@ -76,7 +76,7 @@
},
"Control": "FlaxEngine.GUI.Label",
"Data": {
"Text": "eFPS: 15 uTime: 297.4087306\nuFPS: 15 uTime: 0.00833330024033785\nrFPS: 15 rTime: 0\npFPS: 30 pTime: 0",
"Text": "eFPS: 118 uTime: 44.9332779\nuFPS: 120 uTime: 0.00833330024033785\nrFPS: 120 rTime: 0\npFPS: 30 pTime: 0",
"TextColor": {
"R": 1.0,
"G": 1.0,
@@ -123,7 +123,7 @@
},
"Offsets": {
"Left": 0.0,
"Right": 224.0,
"Right": 231.0,
"Top": -97.0,
"Bottom": 64.0
},
@@ -237,7 +237,8 @@
},
{
"ID": "5a96096947dadddc8576978ffc6ee455",
"TypeName": "Game.CameraSpring",
"PrefabID": "82e58c9d462fba5a0df1a599417ff684",
"PrefabObjectID": "1b648b37406d810fecb8e1ba45a51c84",
"ParentID": "f4ab880f47cab1ca423ce8b04f524ac2",
"V": {}
},
@@ -320,6 +321,17 @@
"PrefabID": "82e58c9d462fba5a0df1a599417ff684",
"PrefabObjectID": "3932111d4c6f925a7b4a2e912307c82a",
"ParentID": "59cc65774b36b4a58a274fb7b4e9d490"
},
{
"ID": "fd4a1e8447db1c20c62974aa57fc205f",
"PrefabID": "82e58c9d462fba5a0df1a599417ff684",
"PrefabObjectID": "12cd95b64f5145dcae7b28b7404ef512",
"ParentID": "59cc65774b36b4a58a274fb7b4e9d490",
"Buffer": {
"Entries": [
{}
]
}
}
]
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -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)
{

View File

@@ -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");
}