player jump fixes, player eye offset

This commit is contained in:
GoaLitiuM
2021-09-13 18:30:40 +03:00
parent 7ed2f712b2
commit 582b1782e4
3 changed files with 72 additions and 66 deletions

View File

@@ -1,12 +1,26 @@
{
"ID": "2d0e518b47d735c98312dd87cc42d6d7",
"TypeName": "FlaxEngine.Prefab",
"EngineBuild": 6224,
"EngineBuild": 6225,
"Data": [
{
"ID": "999a202c47de967d2bdfd09abcc6df4e",
"TypeName": "FlaxEngine.RigidBody",
"Name": "PlayerPrefab",
"Transform": {
"Translation": {
"X": 55.27312469482422,
"Y": 20.41858673095703,
"Z": -32.30524444580078
},
"Orientation": {
"X": 0.0,
"Y": 1.0,
"Z": -0.0,
"W": -4.371138828673793e-8
}
},
"StaticFlags": 0,
"OverrideMass": true,
"Mass": 10.0,
"LinearDamping": 0.0,
@@ -19,13 +33,16 @@
"ID": "b29a58f545071ca393afaab21faa83ad",
"TypeName": "Game.PlayerMovement",
"ParentID": "999a202c47de967d2bdfd09abcc6df4e",
"V": {}
"V": {
"JumpLandSound": "a9ae0bbf438b4e841277f39c3d7c7c8b"
}
},
{
"ID": "a67383834fc3f6f1106e8099e5557e32",
"TypeName": "FlaxEngine.EmptyActor",
"ParentID": "999a202c47de967d2bdfd09abcc6df4e",
"Name": "RootActor"
"Name": "RootActor",
"StaticFlags": 0
},
{
"ID": "b8fc420f4efe96fa2b4042bd98fd3e74",
@@ -35,17 +52,19 @@
"Transform": {
"Translation": {
"X": 0.0,
"Y": 28.7337646484375,
"Y": 22.0,
"Z": 0.0
}
},
"StaticFlags": 0,
"Near": 1.0
},
{
"ID": "226bdb004e72848777178a9d1f207cbf",
"TypeName": "FlaxEngine.AudioListener",
"ParentID": "b8fc420f4efe96fa2b4042bd98fd3e74",
"Name": "AudioListener"
"Name": "AudioListener",
"StaticFlags": 0
},
{
"ID": "8bd80bca49ac35da66aabaa2e473851d",
@@ -61,6 +80,7 @@
"W": 0.7071068286895752
}
},
"StaticFlags": 0,
"ContactOffset": 0.0,
"Material": "d99b8b6f40198beea4703dadd642150e",
"Radius": 16.0,
@@ -71,12 +91,13 @@
"TypeName": "FlaxEngine.BoxCollider",
"ParentID": "999a202c47de967d2bdfd09abcc6df4e",
"Name": "BoxCollider",
"StaticFlags": 0,
"ContactOffset": 0.0,
"Material": "ffe0e84c49607480f67a3994a7fe11a8",
"Size": {
"X": 32.0,
"Y": 84.0,
"Z": 32.0
"X": 30.0,
"Y": 56.0,
"Z": 30.0
}
},
{
@@ -92,6 +113,7 @@
"Z": 0.3199999928474426
}
},
"StaticFlags": 0,
"CollisionData": "593d92914c4bd54679ddec9e539bba80"
}
]

View File

@@ -27,72 +27,50 @@
"ID": "6c66fa4a4a5de8998eb84388d1648317",
"PrefabID": "2d0e518b47d735c98312dd87cc42d6d7",
"PrefabObjectID": "999a202c47de967d2bdfd09abcc6df4e",
"ParentID": "194e05f445ece24ec5448d886e1334df",
"Transform": {
"Translation": {
"X": 55.27312469482422,
"Y": 20.41858673095703,
"Z": -32.30524444580078
},
"Orientation": {
"X": 0.0,
"Y": 1.0,
"Z": -0.0,
"W": -4.371138828673793e-8
}
},
"StaticFlags": 0
"ParentID": "194e05f445ece24ec5448d886e1334df"
},
{
"ID": "d5c84d67417ddf09908c76b6f0582b43",
"PrefabID": "2d0e518b47d735c98312dd87cc42d6d7",
"PrefabObjectID": "b29a58f545071ca393afaab21faa83ad",
"ParentID": "6c66fa4a4a5de8998eb84388d1648317",
"V": {
"JumpLandSound": "a9ae0bbf438b4e841277f39c3d7c7c8b"
}
"V": {}
},
{
"ID": "d1a76c334a514c99f8f5b2bd81abae2c",
"PrefabID": "2d0e518b47d735c98312dd87cc42d6d7",
"PrefabObjectID": "a67383834fc3f6f1106e8099e5557e32",
"ParentID": "6c66fa4a4a5de8998eb84388d1648317",
"StaticFlags": 0
"ParentID": "6c66fa4a4a5de8998eb84388d1648317"
},
{
"ID": "357077e9405b2a7ba50198bbed8bd5f9",
"PrefabID": "2d0e518b47d735c98312dd87cc42d6d7",
"PrefabObjectID": "b8fc420f4efe96fa2b4042bd98fd3e74",
"ParentID": "d1a76c334a514c99f8f5b2bd81abae2c",
"StaticFlags": 0
"ParentID": "d1a76c334a514c99f8f5b2bd81abae2c"
},
{
"ID": "905d23324e7f98c9f8287e8e49a83981",
"PrefabID": "2d0e518b47d735c98312dd87cc42d6d7",
"PrefabObjectID": "226bdb004e72848777178a9d1f207cbf",
"ParentID": "357077e9405b2a7ba50198bbed8bd5f9",
"StaticFlags": 0
"ParentID": "357077e9405b2a7ba50198bbed8bd5f9"
},
{
"ID": "89c02cd64b640185d9947ab451453c4c",
"PrefabID": "2d0e518b47d735c98312dd87cc42d6d7",
"PrefabObjectID": "8bd80bca49ac35da66aabaa2e473851d",
"ParentID": "6c66fa4a4a5de8998eb84388d1648317",
"StaticFlags": 0
"ParentID": "6c66fa4a4a5de8998eb84388d1648317"
},
{
"ID": "eebdb91647732ad3dfc7528c978cd19c",
"PrefabID": "2d0e518b47d735c98312dd87cc42d6d7",
"PrefabObjectID": "d9d61d314ad79d49ba08059cef50f802",
"ParentID": "6c66fa4a4a5de8998eb84388d1648317",
"StaticFlags": 0
"ParentID": "6c66fa4a4a5de8998eb84388d1648317"
},
{
"ID": "3e0f83fe407b2d9ed7c734a62fad0826",
"PrefabID": "2d0e518b47d735c98312dd87cc42d6d7",
"PrefabObjectID": "b377cc03418270d87e8a5b92cb5374ea",
"ParentID": "6c66fa4a4a5de8998eb84388d1648317",
"StaticFlags": 0
"ParentID": "6c66fa4a4a5de8998eb84388d1648317"
},
{
"ID": "ff6b6db54b5aa08e7286ef86246149ef",

View File

@@ -302,6 +302,7 @@ namespace Game
return traceInfo;
}
#if FLAX_EDITOR
public override void OnDebugDraw()
{
base.OnDebugDraw();
@@ -327,6 +328,7 @@ namespace Game
DebugDraw.DrawWireBox(boxCollider.OrientedBox.GetBoundingBox(), Color.GreenYellow * 0.8f);
}
}
#endif
private SlideMoveHit StepSlideMove(ref Vector3 position, ref Vector3 velocity, bool onGround)
{
@@ -592,9 +594,11 @@ namespace Game
private const float strafeAcceleration = 10f; //QW
private const float airControl = 0f; //CPM
private const float stepSize = 16f;
private const float autoJumpTime = 0.4f;
//private bool physicsInteractions = false;
private bool jumped = false;
private float lastJumped = -1f;
private Vector3 safePosition;
@@ -675,10 +679,16 @@ namespace Game
// TODO: snap to ground here
// jump
if (onGround)
{
if (!jumped && InputManager.GetAction("Jump"))
bool jumpAction = InputManager.GetAction("Jump");
if (jumped && !jumpAction)
jumped = false; // jump released
else if (jumped && Time.GameTime - lastJumped >= autoJumpTime)
jumped = false; // jump timeout
if (onGround && jumpAction && !jumped)
{
Console.Print("jumping");
// reset velocity from gravity
if (-Vector3.Dot(Physics.Gravity.Normalized, velocity) < 0 &&
Vector3.Dot(velocity, traceGround.hitNormal) < -0.1)
@@ -688,6 +698,8 @@ namespace Game
velocity += Vector3.Up * jumpVelocity;
onGround = false;
jumped = true;
lastJumped = Time.GameTime;
if (JumpLandSound != null && JumpLandSound.IsLoaded)
{
@@ -695,17 +707,11 @@ namespace Game
audioSource.Clip = JumpLandSound;
audioSource.Position = rootActor.Position; //new Vector3(-350, 176, 61);//rootActor.Position;
audioSource.Parent = Actor.Parent;
audioSource.Pitch = 1f;
audioSource.Play();
Destroy(audioSource, JumpLandSound.Length);
}
else if (JumpLandSound == null)
Console.Print("jumpAsset not found");
else
Console.Print("jumpAsset not loaded");
}
else if (jumped) // jump released
jumped = false;
}
// ground friction