more stuf
This commit is contained in:
Binary file not shown.
BIN
Assets/Cylinders/cylinder_20.fbx
Normal file
BIN
Assets/Cylinders/cylinder_20.fbx
Normal file
Binary file not shown.
BIN
Assets/Cylinders/cylinder_20_tfan.fbx
Normal file
BIN
Assets/Cylinders/cylinder_20_tfan.fbx
Normal file
Binary file not shown.
Binary file not shown.
BIN
Assets/Cylinders/cylinder_32_tfan.fbx
Normal file
BIN
Assets/Cylinders/cylinder_32_tfan.fbx
Normal file
Binary file not shown.
Binary file not shown.
BIN
Assets/Cylinders/cylinder_shapes.blend1
Normal file
BIN
Assets/Cylinders/cylinder_shapes.blend1
Normal file
Binary file not shown.
36528
Assets/__aerowalk.obj
Normal file
36528
Assets/__aerowalk.obj
Normal file
File diff suppressed because it is too large
Load Diff
BIN
Assets/aerowalk.fbx
Normal file
BIN
Assets/aerowalk.fbx
Normal file
Binary file not shown.
92
Assets/aerowalk_uv.mtl
Normal file
92
Assets/aerowalk_uv.mtl
Normal file
@@ -0,0 +1,92 @@
|
||||
# Blender MTL File: 'None'
|
||||
# Material Count: 9
|
||||
|
||||
newmtl common/clip
|
||||
Ns 0.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.800000 0.800000 0.800000
|
||||
Ks 0.000000 0.000000 0.000000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.450000
|
||||
d 1.000000
|
||||
illum 1
|
||||
|
||||
newmtl common/trigger
|
||||
Ns 0.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.800000 0.800000 0.800000
|
||||
Ks 0.000000 0.000000 0.000000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.450000
|
||||
d 1.000000
|
||||
illum 1
|
||||
|
||||
newmtl dev/dev_128_blue
|
||||
Ns 0.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.800000 0.800000 0.800000
|
||||
Ks 0.000000 0.000000 0.000000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.450000
|
||||
d 1.000000
|
||||
illum 1
|
||||
|
||||
newmtl dev/dev_128_gray
|
||||
Ns 0.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.800000 0.800000 0.800000
|
||||
Ks 0.000000 0.000000 0.000000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.450000
|
||||
d 1.000000
|
||||
illum 1
|
||||
|
||||
newmtl dev/dev_128_green
|
||||
Ns 0.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.800000 0.800000 0.800000
|
||||
Ks 0.000000 0.000000 0.000000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.450000
|
||||
d 1.000000
|
||||
illum 1
|
||||
|
||||
newmtl dev/dev_128_lightgray
|
||||
Ns 0.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.800000 0.800000 0.800000
|
||||
Ks 0.000000 0.000000 0.000000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.450000
|
||||
d 1.000000
|
||||
illum 1
|
||||
|
||||
newmtl dev/dev_128_red
|
||||
Ns 0.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.800000 0.800000 0.800000
|
||||
Ks 0.000000 0.000000 0.000000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.450000
|
||||
d 1.000000
|
||||
illum 1
|
||||
|
||||
newmtl dev/dev_128_white
|
||||
Ns 0.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.800000 0.800000 0.800000
|
||||
Ks 0.000000 0.000000 0.000000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.450000
|
||||
d 1.000000
|
||||
illum 1
|
||||
|
||||
newmtl dev/dev_128_yellow
|
||||
Ns 0.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.800000 0.800000 0.800000
|
||||
Ks 0.000000 0.000000 0.000000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.450000
|
||||
d 1.000000
|
||||
illum 1
|
||||
19993
Assets/aerowalk_uv.obj
Normal file
19993
Assets/aerowalk_uv.obj
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,13 +1,14 @@
|
||||
{
|
||||
"ID": "3c7bc3854d42f9b1b0fea9ba0d7fa8e9",
|
||||
"TypeName": "FlaxEditor.Content.Settings.GameSettings",
|
||||
"EngineBuild": 6217,
|
||||
"EngineBuild": 6219,
|
||||
"Data": {
|
||||
"ProductName": "Goake",
|
||||
"CompanyName": "GoaLitiuM",
|
||||
"FirstScene": "0733cc9b40d3d05366be64bbd9b59e21",
|
||||
"NoSplashScreen": true,
|
||||
"Time": "a55dc3c04da4ea3744b7f1994565beac",
|
||||
"LayersAndTags": "60078f6a489f7c57e47fce83afaada66",
|
||||
"Physics": "4bd8a4cc460399b5f1975fbe0a668e3f",
|
||||
"Input": "8ec53dba4c238bfbea1d62922e612a4d",
|
||||
"Graphics": "f94d5aae457aeba67033a8a4ca753214",
|
||||
|
||||
Binary file not shown.
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ID": "ffe0e84c49607480f67a3994a7fe11a8",
|
||||
"TypeName": "FlaxEngine.PhysicalMaterial",
|
||||
"EngineBuild": 6217,
|
||||
"EngineBuild": 6219,
|
||||
"Data": {
|
||||
"Friction": 30.0,
|
||||
"FrictionCombineMode": 2,
|
||||
"OverrideFrictionCombineMode": false,
|
||||
"Friction": 0.0,
|
||||
"FrictionCombineMode": 1,
|
||||
"OverrideFrictionCombineMode": true,
|
||||
"Restitution": 0.0,
|
||||
"RestitutionCombineMode": 1,
|
||||
"OverrideRestitutionCombineMode": true
|
||||
|
||||
13
Content/PhysicsMaterials/Slippery.json
Normal file
13
Content/PhysicsMaterials/Slippery.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"ID": "446e65214a3fc41f5815b79e5f3ea42f",
|
||||
"TypeName": "FlaxEngine.PhysicalMaterial",
|
||||
"EngineBuild": 6218,
|
||||
"Data": {
|
||||
"Friction": 0.0,
|
||||
"FrictionCombineMode": 0,
|
||||
"OverrideFrictionCombineMode": false,
|
||||
"Restitution": 0.06394104,
|
||||
"RestitutionCombineMode": 0,
|
||||
"OverrideRestitutionCombineMode": false
|
||||
}
|
||||
}
|
||||
13
Content/PhysicsMaterials/Sticky.json
Normal file
13
Content/PhysicsMaterials/Sticky.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"ID": "86deaa144528c2abae0be683580ddb4d",
|
||||
"TypeName": "FlaxEngine.PhysicalMaterial",
|
||||
"EngineBuild": 6218,
|
||||
"Data": {
|
||||
"Friction": 999999.0,
|
||||
"FrictionCombineMode": 3,
|
||||
"OverrideFrictionCombineMode": true,
|
||||
"Restitution": 0.0,
|
||||
"RestitutionCombineMode": 0,
|
||||
"OverrideRestitutionCombineMode": false
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"ID": "8ec53dba4c238bfbea1d62922e612a4d",
|
||||
"TypeName": "FlaxEditor.Content.Settings.InputSettings",
|
||||
"EngineBuild": 6217,
|
||||
"EngineBuild": 6219,
|
||||
"Data": {
|
||||
"ActionMappings": [
|
||||
{
|
||||
@@ -67,6 +67,14 @@
|
||||
"MouseButton": 3,
|
||||
"GamepadButton": 0,
|
||||
"Gamepad": 0
|
||||
},
|
||||
{
|
||||
"Name": "ClearConsole",
|
||||
"Mode": 1,
|
||||
"Key": 66,
|
||||
"MouseButton": 3,
|
||||
"GamepadButton": 0,
|
||||
"Gamepad": 0
|
||||
}
|
||||
],
|
||||
"AxisMappings": [
|
||||
|
||||
42
Content/Settings/LayersAndTagsSettings.json
Normal file
42
Content/Settings/LayersAndTagsSettings.json
Normal file
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"ID": "60078f6a489f7c57e47fce83afaada66",
|
||||
"TypeName": "FlaxEditor.Content.Settings.LayersAndTagsSettings",
|
||||
"EngineBuild": 6219,
|
||||
"Data": {
|
||||
"Tags": [],
|
||||
"Layers": [
|
||||
"DefaultLayer",
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"ID": "4bd8a4cc460399b5f1975fbe0a668e3f",
|
||||
"TypeName": "FlaxEditor.Content.Settings.PhysicsSettings",
|
||||
"EngineBuild": 6217,
|
||||
"EngineBuild": 6219,
|
||||
"Data": {
|
||||
"DefaultGravity": {
|
||||
"X": 0.0,
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"ID": "a55dc3c04da4ea3744b7f1994565beac",
|
||||
"TypeName": "FlaxEditor.Content.Settings.TimeSettings",
|
||||
"EngineBuild": 6218,
|
||||
"EngineBuild": 6219,
|
||||
"Data": {
|
||||
"UpdateFPS": 60.0,
|
||||
"UpdateFPS": 0.0,
|
||||
"PhysicsFPS": 60.0,
|
||||
"DrawFPS": 60.0,
|
||||
"DrawFPS": 0.0,
|
||||
"TimeScale": 1.0,
|
||||
"MaxUpdateDeltaTime": 0.1
|
||||
}
|
||||
|
||||
BIN
Content/Shapes/cylinder_12.flax
Normal file
BIN
Content/Shapes/cylinder_12.flax
Normal file
Binary file not shown.
BIN
Content/Shapes/cylinder_128.flax
Normal file
BIN
Content/Shapes/cylinder_128.flax
Normal file
Binary file not shown.
BIN
Content/Shapes/cylinder_128_collision.flax
Normal file
BIN
Content/Shapes/cylinder_128_collision.flax
Normal file
Binary file not shown.
BIN
Content/Shapes/cylinder_12_collision.flax
Normal file
BIN
Content/Shapes/cylinder_12_collision.flax
Normal file
Binary file not shown.
BIN
Content/Shapes/cylinder_16.flax
Normal file
BIN
Content/Shapes/cylinder_16.flax
Normal file
Binary file not shown.
BIN
Content/Shapes/cylinder_16_collision.flax
Normal file
BIN
Content/Shapes/cylinder_16_collision.flax
Normal file
Binary file not shown.
BIN
Content/Shapes/cylinder_24.flax
Normal file
BIN
Content/Shapes/cylinder_24.flax
Normal file
Binary file not shown.
BIN
Content/Shapes/cylinder_24_collision.flax
Normal file
BIN
Content/Shapes/cylinder_24_collision.flax
Normal file
Binary file not shown.
Binary file not shown.
BIN
Content/Shapes/cylinder_32_collision.flax
Normal file
BIN
Content/Shapes/cylinder_32_collision.flax
Normal file
Binary file not shown.
BIN
Content/Shapes/cylinder_48.flax
Normal file
BIN
Content/Shapes/cylinder_48.flax
Normal file
Binary file not shown.
BIN
Content/Shapes/cylinder_48_collision.flax
Normal file
BIN
Content/Shapes/cylinder_48_collision.flax
Normal file
Binary file not shown.
BIN
Content/Shapes/cylinder_64.flax
Normal file
BIN
Content/Shapes/cylinder_64.flax
Normal file
Binary file not shown.
BIN
Content/Shapes/cylinder_64_collision.flax
Normal file
BIN
Content/Shapes/cylinder_64_collision.flax
Normal file
Binary file not shown.
BIN
Content/Shapes/cylinder_8.flax
Normal file
BIN
Content/Shapes/cylinder_8.flax
Normal file
Binary file not shown.
BIN
Content/Shapes/cylinder_8_collision.flax
Normal file
BIN
Content/Shapes/cylinder_8_collision.flax
Normal file
Binary file not shown.
Binary file not shown.
@@ -92,6 +92,9 @@ namespace Cabrito
|
||||
// Closes the Console
|
||||
public static void Close() => instance.Close();
|
||||
|
||||
// Clears the content of the Console
|
||||
public static void Clear() => instance.Clear();
|
||||
|
||||
public static void Execute(string str) => instance.Execute(str);
|
||||
|
||||
public static string GetVariable(string variableName) => instance.GetVariable(variableName);
|
||||
@@ -299,6 +302,12 @@ namespace Cabrito
|
||||
stopwatch.Restart();
|
||||
}
|
||||
|
||||
// Clears the content of the Console
|
||||
public void Clear()
|
||||
{
|
||||
consoleLines.Clear();
|
||||
}
|
||||
|
||||
public void Execute(string str)
|
||||
{
|
||||
str = str.Trim();
|
||||
|
||||
@@ -7,15 +7,11 @@ namespace Game
|
||||
{
|
||||
public class ConsolePlugin : GamePlugin
|
||||
{
|
||||
public ConsolePlugin()
|
||||
{
|
||||
Console.Init();
|
||||
Console.Print("ConsolePlugin ctor");
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
Console.Init();
|
||||
base.Initialize();
|
||||
|
||||
Console.Print("ConsolePlugin initialize");
|
||||
}
|
||||
|
||||
|
||||
@@ -260,8 +260,6 @@ namespace Cabrito
|
||||
var rootlocation = rootControl.Control.Location;
|
||||
rootlocation.Y = -rootControl.Control.Height;
|
||||
rootControl.Control.Location = rootlocation;
|
||||
|
||||
Console.Print("console open: " + Console.IsOpen.ToString());
|
||||
}
|
||||
|
||||
private void OnSendLog(LogType level, string msg, FlaxEngine.Object obj, string stackTrace)
|
||||
@@ -331,6 +329,7 @@ namespace Cabrito
|
||||
|
||||
public void OnConsoleClose()
|
||||
{
|
||||
Console.Print("closed console");
|
||||
Screen.CursorVisible = false;
|
||||
Screen.CursorLock = CursorLockMode.Locked;
|
||||
|
||||
@@ -345,12 +344,15 @@ namespace Cabrito
|
||||
{
|
||||
base.OnUpdate();
|
||||
|
||||
if (!Console.IsOpen && Input.GetAction("ClearConsole"))
|
||||
Console.Clear();
|
||||
|
||||
float targetY;
|
||||
float conHeight = rootControl.Control.Height /*/ Platform.DpiScale*/;
|
||||
if (!Console.IsOpen)
|
||||
targetY = -conHeight;
|
||||
else
|
||||
targetY = 0.0f;
|
||||
targetY = 0.0f;
|
||||
|
||||
Vector2 location = rootControl.Control.Location;
|
||||
if (location.Y != targetY)
|
||||
|
||||
@@ -3,11 +3,11 @@ using FlaxEngine;
|
||||
using Cabrito;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using FlaxEditor.Utilities;
|
||||
using FlaxEngine.Assertions;
|
||||
|
||||
namespace Game
|
||||
{
|
||||
public struct TraceInfo
|
||||
public struct TraceInfo_Old
|
||||
{
|
||||
public RayCastHit[] hitInfos;
|
||||
public bool startSolid;
|
||||
@@ -35,7 +35,10 @@ namespace Game
|
||||
|
||||
private InputEvent onExit = new InputEvent("Exit");
|
||||
|
||||
private const float collisionMargin = 0.031f * 1.666f;
|
||||
|
||||
Actor rootActor;
|
||||
private RigidBody rigidBody;
|
||||
public override void OnAwake()
|
||||
{
|
||||
base.OnAwake();
|
||||
@@ -47,6 +50,47 @@ namespace Game
|
||||
};
|
||||
|
||||
rootActor = Actor.GetChild(0);
|
||||
|
||||
rigidBody = Actor.As<RigidBody>();
|
||||
rigidBody.CollisionEnter += OnCollisionEnter;
|
||||
rigidBody.TriggerEnter += OnTriggerEnter;
|
||||
rigidBody.TriggerExit += OnTriggerExit;
|
||||
|
||||
/*proxyBody.CollisionEnter += delegate(Collision collision) {
|
||||
if (collision.OtherActor.AttachedRigidBody != null)
|
||||
{
|
||||
proxyCollision = true;
|
||||
}
|
||||
};
|
||||
proxyBody.CollisionExit += delegate(Collision collision) {
|
||||
if (collision.OtherActor.AttachedRigidBody != null)
|
||||
{
|
||||
proxyCollision = false;
|
||||
}
|
||||
};*/
|
||||
}
|
||||
|
||||
private List<PhysicsColliderActor> touchingActors = new List<PhysicsColliderActor>();
|
||||
private void OnTriggerEnter(PhysicsColliderActor colliderActor)
|
||||
{
|
||||
//if (colliderActor.AttachedRigidBody == null)
|
||||
// return;
|
||||
touchingActors.Add(colliderActor);
|
||||
Console.Print("trogger: ");
|
||||
}
|
||||
|
||||
private void OnTriggerExit(PhysicsColliderActor colliderActor)
|
||||
{
|
||||
//if (colliderActor.AttachedRigidBody == null)
|
||||
// return;
|
||||
|
||||
touchingActors.Remove(colliderActor);
|
||||
Console.Print("untrogger: ");
|
||||
}
|
||||
|
||||
private void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
//Console.Print("collision: ");
|
||||
}
|
||||
|
||||
public override void OnDestroy()
|
||||
@@ -64,10 +108,78 @@ namespace Game
|
||||
viewRoll = initialEulerAngles.Z;
|
||||
}
|
||||
|
||||
private TraceInfo TracePlayer(Vector3 start, Vector3 end)
|
||||
/// <summary>
|
||||
/// Checks for overlapping colliders in place using the player's rigidbody.
|
||||
/// </summary>
|
||||
/// <param name="position">Position</param>
|
||||
/// <returns></returns>
|
||||
private Collider[] TracePlayer(Vector3 position, float extra = 0.0f)
|
||||
{
|
||||
Collider[] colliders = null;
|
||||
|
||||
bool collided = false;
|
||||
var capsuleCollider = Actor.GetChild<CapsuleCollider>();
|
||||
var boxCollider = Actor.GetChild<BoxCollider>();
|
||||
var meshCollider = Actor.GetChild<MeshCollider>();
|
||||
PhysicsColliderActor colliderActor = null;
|
||||
if (capsuleCollider && capsuleCollider.IsActive)
|
||||
{
|
||||
colliderActor = capsuleCollider;
|
||||
collided = Physics.OverlapCapsule(position,
|
||||
capsuleCollider.Radius + extra, capsuleCollider.Height + extra,
|
||||
out colliders, capsuleCollider.Orientation,
|
||||
uint.MaxValue,
|
||||
false);
|
||||
}
|
||||
else if (meshCollider && meshCollider.IsActive)
|
||||
{
|
||||
colliderActor = meshCollider;
|
||||
collided = Physics.OverlapConvex(position,
|
||||
meshCollider.CollisionData, meshCollider.Scale + extra,
|
||||
out colliders, meshCollider.Orientation,
|
||||
uint.MaxValue,
|
||||
false);
|
||||
}
|
||||
else if (boxCollider && boxCollider.IsActive)
|
||||
{
|
||||
colliderActor = boxCollider;
|
||||
collided = Physics.OverlapBox(position,
|
||||
boxCollider.OrientedBox.Extents + extra,
|
||||
out colliders, boxCollider.Orientation,
|
||||
uint.MaxValue,
|
||||
false);
|
||||
}
|
||||
else
|
||||
Assert.Fail("No supported colliders found for rigidbody");
|
||||
|
||||
if (!collided)
|
||||
return colliders;
|
||||
|
||||
List<Collider> collidersFiltered = new List<Collider>();
|
||||
foreach (var collider in colliders)
|
||||
{
|
||||
if (collider == colliderActor)
|
||||
continue;
|
||||
|
||||
collidersFiltered.Add(collider);
|
||||
}
|
||||
|
||||
if (collidersFiltered.Count == 0)
|
||||
return colliders; // self-collision?
|
||||
|
||||
return collidersFiltered.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sweeps the player rigidbody in world and returns geometry which was hit during the trace.
|
||||
/// </summary>
|
||||
/// <param name="start">Start position</param>
|
||||
/// <param name="end">End position</param>
|
||||
/// <returns></returns>
|
||||
private TraceInfo TracePlayer(Vector3 start, Vector3 end, float tolerance = 0.0f)
|
||||
{
|
||||
TraceInfo traceInfo = new TraceInfo();
|
||||
|
||||
|
||||
Vector3 delta = end - start;
|
||||
float maxDistance = delta.Length;
|
||||
Vector3 direction = delta.Normalized;
|
||||
@@ -81,7 +193,7 @@ namespace Game
|
||||
{
|
||||
colliderActor = capsuleCollider;
|
||||
collided = Physics.CapsuleCastAll(start,
|
||||
capsuleCollider.Radius, capsuleCollider.Height,
|
||||
capsuleCollider.Radius + tolerance, capsuleCollider.Height,
|
||||
direction, out traceInfo.hitInfos, capsuleCollider.Orientation, maxDistance,
|
||||
uint.MaxValue,
|
||||
false);
|
||||
@@ -90,16 +202,16 @@ namespace Game
|
||||
{
|
||||
colliderActor = meshCollider;
|
||||
collided = Physics.ConvexCastAll(start,
|
||||
meshCollider.CollisionData,
|
||||
direction, out traceInfo.hitInfos, capsuleCollider.Orientation, maxDistance,
|
||||
uint.MaxValue,
|
||||
false);
|
||||
meshCollider.CollisionData, meshCollider.Scale + tolerance,
|
||||
direction, out traceInfo.hitInfos, meshCollider.Orientation, maxDistance,
|
||||
uint.MaxValue,
|
||||
false);
|
||||
}
|
||||
else if (boxCollider && boxCollider.IsActive)
|
||||
{
|
||||
colliderActor = boxCollider;
|
||||
collided = Physics.BoxCastAll(start,
|
||||
boxCollider.OrientedBox.Extents,
|
||||
boxCollider.OrientedBox.Extents + tolerance,
|
||||
direction, out traceInfo.hitInfos, boxCollider.Orientation, maxDistance, uint.MaxValue,
|
||||
false);
|
||||
}
|
||||
@@ -113,17 +225,28 @@ namespace Game
|
||||
{
|
||||
if (hitInfo.Collider == colliderActor)
|
||||
continue;
|
||||
|
||||
|
||||
hitInfosFiltered.Add(hitInfo);
|
||||
|
||||
if (hitInfo.Distance < closest.Distance)
|
||||
if (hitInfo.Distance < closest.Distance && hitInfo.Distance != 0.0f)
|
||||
closest = hitInfo;
|
||||
}
|
||||
|
||||
traceInfo.hitInfos = hitInfosFiltered.ToArray();
|
||||
|
||||
if (closest.Distance > 0f)
|
||||
if (hitInfosFiltered.Count == 0)
|
||||
collided = false; // self-collision?
|
||||
else //if (closest.Distance > 0f)
|
||||
{
|
||||
if (closest.Distance == float.MaxValue)
|
||||
{
|
||||
foreach (var hitInfo in hitInfosFiltered)
|
||||
{
|
||||
if (hitInfo.Distance < closest.Distance)
|
||||
closest = hitInfo;
|
||||
}
|
||||
}
|
||||
|
||||
traceInfo.hitInfos = hitInfosFiltered.ToArray();
|
||||
|
||||
traceInfo.fraction = closest.Distance / maxDistance;
|
||||
traceInfo.hitNormal = closest.Normal;
|
||||
traceInfo.hitPosition = closest.Point;
|
||||
@@ -132,13 +255,14 @@ namespace Game
|
||||
if (traceInfo.fraction == 0f && maxDistance > 0f)
|
||||
traceInfo.startSolid = true;
|
||||
}
|
||||
else
|
||||
/*else
|
||||
{
|
||||
traceInfo.startSolid = true;
|
||||
traceInfo.fraction = 0f;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
else
|
||||
|
||||
if (!collided)
|
||||
{
|
||||
traceInfo.hitInfos = new RayCastHit[0];
|
||||
traceInfo.fraction = 1f;
|
||||
@@ -154,16 +278,17 @@ namespace Game
|
||||
|
||||
var capsuleCollider = Actor.GetChild<CapsuleCollider>();
|
||||
var boxCollider = Actor.GetChild<BoxCollider>();
|
||||
var rigidBody = Actor.As<RigidBody>();
|
||||
var meshCollider = Actor.GetChild<MeshCollider>();
|
||||
if (capsuleCollider && capsuleCollider.IsActive)
|
||||
{
|
||||
Quaternion rotation = capsuleCollider.LocalOrientation * Quaternion.Euler(0f, 90f, 0f);
|
||||
if (cylinderShape)
|
||||
{
|
||||
DebugDraw.DrawWireBox(capsuleCollider.Box, Color.GreenYellow * 0.8f);
|
||||
}
|
||||
|
||||
DebugDraw.DrawWireTube(rigidBody.Position, rotation, capsuleCollider.Radius, capsuleCollider.Height, Color.GreenYellow * 0.8f);
|
||||
DebugDraw.DrawWireTube(capsuleCollider.Position, rotation, capsuleCollider.Radius, capsuleCollider.Height, Color.GreenYellow * 0.8f);
|
||||
}
|
||||
else if (meshCollider && meshCollider.IsActive)
|
||||
{
|
||||
//Quaternion rotation = meshCollider.LocalOrientation * Quaternion.Euler(0f, 90f, 0f);
|
||||
DebugDraw.DrawWireCylinder(meshCollider.Position, meshCollider.Orientation, capsuleCollider.Radius, capsuleCollider.Height + capsuleCollider.Radius * 2, Color.GreenYellow * 0.8f);
|
||||
//DebugDraw.DrawWireTube(meshCollider.Position, rotation, meshCollider.Radius, meshCollider.Height, Color.GreenYellow * 0.8f);
|
||||
}
|
||||
else if (boxCollider && boxCollider.IsActive)
|
||||
{
|
||||
@@ -187,7 +312,6 @@ namespace Game
|
||||
{
|
||||
Vector3 startPos = position;
|
||||
Vector3 endPos = position + (velocity * timeleft);
|
||||
float distt = (endPos - startPos).Length;
|
||||
|
||||
TraceInfo trace = TracePlayer(startPos, endPos);
|
||||
// TODO: handle portals here
|
||||
@@ -201,6 +325,20 @@ namespace Game
|
||||
break;
|
||||
}
|
||||
|
||||
if (physicsInteractions)
|
||||
{
|
||||
RigidBody rigidBody = Actor.As<RigidBody>();
|
||||
foreach (var hit in trace.hitInfos)
|
||||
{
|
||||
if (hit.Collider.AttachedRigidBody == null || hit.Collider.AttachedRigidBody.IsKinematic)
|
||||
continue;
|
||||
|
||||
Vector3 force = -hit.Normal * velocity.Length * rigidBody.Mass;
|
||||
//Console.Print("move force: " + (force.Length / timeleft));
|
||||
hit.Collider.AttachedRigidBody.AddForce(force, ForceMode.Force);
|
||||
}
|
||||
}
|
||||
|
||||
if (fraction > 0f)
|
||||
{
|
||||
position = trace.endPosition;
|
||||
@@ -238,7 +376,7 @@ namespace Game
|
||||
Vector3 normal = hitNormals[plane];
|
||||
|
||||
// clip velocity
|
||||
velocity = velocity - normal * Vector3.Dot(velocity, normal);
|
||||
velocity -= normal * Vector3.Dot(velocity, normal);
|
||||
//velocity = Vector3.ProjectOnPlane(velocity, normal);
|
||||
|
||||
//traceOffset = normal * 1f;
|
||||
@@ -260,7 +398,7 @@ namespace Game
|
||||
}
|
||||
|
||||
// push off slightly away from the walls to not get stuck
|
||||
position += normalMargin.Normalized * 0.031f;
|
||||
position += normalMargin.Normalized * collisionMargin;
|
||||
|
||||
if (plane == hitNormals.Count)
|
||||
{
|
||||
@@ -293,10 +431,8 @@ namespace Game
|
||||
}
|
||||
}
|
||||
|
||||
//Vector3 wishVelocity = Vector3.Zero;
|
||||
Vector3 gravityVelocity = Vector3.Zero;
|
||||
Vector3 currentVelocity = Vector3.Zero;
|
||||
private bool onGround = false;
|
||||
[ReadOnly]
|
||||
public bool onGround = false;
|
||||
|
||||
private const float friction = 4f;
|
||||
private const float stopspeed = 100f;
|
||||
@@ -310,45 +446,181 @@ namespace Game
|
||||
private const float airStrafeAcceleration = 70f * 0f; //CPM?
|
||||
private const float strafeAcceleration = 10f; //QW
|
||||
private const float airControl = 0f; //CPM
|
||||
private bool physicsInteractions = true;
|
||||
|
||||
private bool jumped = false;
|
||||
|
||||
private bool cylinderShape = true;
|
||||
|
||||
private Vector3 safePosition;
|
||||
|
||||
|
||||
[ReadOnly]
|
||||
public float CurrentVelocity { get { return currentVelocity.Length; } set {} }
|
||||
|
||||
private Vector3 currentVelocity;
|
||||
public override void OnFixedUpdate()
|
||||
{
|
||||
var rigidBody = Actor.As<RigidBody>();
|
||||
var rootTrans = rootActor.Transform;
|
||||
Transform rootTrans = rootActor.Transform;
|
||||
|
||||
var inputDirection = new Vector3(InputManager.GetAxis("Horizontal"), 0.0f, InputManager.GetAxis("Vertical"));
|
||||
var moveDirection = rootTrans.TransformDirection(inputDirection);
|
||||
Vector3 inputDirection = new Vector3(InputManager.GetAxis("Horizontal"), 0.0f, InputManager.GetAxis("Vertical"));
|
||||
Vector3 moveDirection = rootTrans.TransformDirection(inputDirection);
|
||||
|
||||
Vector3 position = rigidBody.Position;
|
||||
Vector3 velocity = rigidBody.LinearVelocity;//currentVelocity;
|
||||
|
||||
Vector3 wishVelocity = Vector3.Zero;
|
||||
if (!inputDirection.IsZero)
|
||||
wishVelocity = moveDirection.Normalized * MoveSpeed;
|
||||
|
||||
#if false
|
||||
Collider[] overlaps = TracePlayer(rigidBody.Position, 0.001f * 0f);
|
||||
if (overlaps.Length > 0)
|
||||
{
|
||||
// overlapping with other objects
|
||||
//Console.Print("overlap");
|
||||
|
||||
Collider playerCollider = null;
|
||||
var capsuleCollider = Actor.GetChild<CapsuleCollider>();
|
||||
var boxCollider = Actor.GetChild<BoxCollider>();
|
||||
var meshCollider = Actor.GetChild<MeshCollider>();
|
||||
if (capsuleCollider && capsuleCollider.IsActive)
|
||||
{
|
||||
playerCollider = capsuleCollider;
|
||||
}
|
||||
else if (meshCollider && meshCollider.IsActive)
|
||||
{
|
||||
playerCollider = meshCollider;
|
||||
|
||||
}
|
||||
else if (boxCollider && boxCollider.IsActive)
|
||||
{
|
||||
playerCollider = boxCollider;
|
||||
}
|
||||
|
||||
foreach (var overlap in overlaps)
|
||||
{
|
||||
if (Collider.ComputePenetration(playerCollider, overlap, out Vector3 direction, out float distance))
|
||||
{
|
||||
//Console.Print("overlap ok");
|
||||
|
||||
var type = overlap.Parent.GetType();
|
||||
if (overlap.Parent.GetType() == typeof(RigidBody))
|
||||
{
|
||||
var otherRigidBody = overlap.Parent.As<RigidBody>();
|
||||
|
||||
var otherMomentum = otherRigidBody.LinearVelocity * otherRigidBody.Mass;
|
||||
var myMomentum = rigidBody.LinearVelocity * rigidBody.Mass;
|
||||
|
||||
var newVelocity = (otherMomentum + myMomentum) / (otherRigidBody.Mass + rigidBody.Mass);
|
||||
|
||||
Console.Print(overlap.Parent.Name + ": "+ newVelocity.Length.ToString());
|
||||
//otherRigidBody.LinearVelocity += -direction.Normalized * newVelocity;
|
||||
otherRigidBody.AddForce(-direction.Normalized * newVelocity, ForceMode.Force);
|
||||
}
|
||||
|
||||
position += direction * (distance + 0.001f);
|
||||
|
||||
/*var oldVelocity = velocity;
|
||||
velocity = direction * (distance + 0.001f);
|
||||
velocity /= Time.DeltaTime;
|
||||
SlideMove(ref position, false, ref velocity);
|
||||
velocity = oldVelocity;*/
|
||||
//position += direction * (distance + 0.001f);
|
||||
//velocity = Vector3.Zero;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Console.Print("overlap safepos");
|
||||
position = safePosition;
|
||||
velocity = Vector3.Zero;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*const float overlapResolveSpeed = 1.0f;
|
||||
|
||||
foreach (var overlap in overlaps)
|
||||
{
|
||||
var overlapRigidbody = overlap.Parent.GetType() == typeof(RigidBody) ? overlap.Parent.As<RigidBody>() : null;
|
||||
if (overlapRigidbody != null)
|
||||
{
|
||||
Vector3 normal = (rigidBody.Position - overlapRigidbody.Position).Normalized;
|
||||
position += normal * overlapResolveSpeed;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
position = safePosition;
|
||||
velocity = Vector3.Zero;
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
#endif
|
||||
bool beingPushed = false;
|
||||
if (touchingActors.Count > 0)
|
||||
beingPushed = true;
|
||||
|
||||
|
||||
|
||||
/*bool beingPushed = false;
|
||||
Collider[] overlaps = TracePlayer(rigidBody.Position);
|
||||
if (overlaps.Length > 0)
|
||||
{
|
||||
//beingPushed = true;
|
||||
|
||||
Collider playerCollider = null;
|
||||
var capsuleCollider = Actor.GetChild<CapsuleCollider>();
|
||||
var boxCollider = Actor.GetChild<BoxCollider>();
|
||||
var meshCollider = Actor.GetChild<MeshCollider>();
|
||||
if (capsuleCollider && capsuleCollider.IsActive)
|
||||
{
|
||||
playerCollider = capsuleCollider;
|
||||
}
|
||||
else if (meshCollider && meshCollider.IsActive)
|
||||
{
|
||||
playerCollider = meshCollider;
|
||||
|
||||
}
|
||||
else if (boxCollider && boxCollider.IsActive)
|
||||
{
|
||||
playerCollider = boxCollider;
|
||||
}
|
||||
|
||||
|
||||
foreach (var overlap in overlaps)
|
||||
{
|
||||
if (Collider.ComputePenetration(playerCollider, overlap, out Vector3 direction, out float distance))
|
||||
{
|
||||
beingPushed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
// categorize position
|
||||
onGround = true;
|
||||
TraceInfo traceGround = TracePlayer(rigidBody.Position, rigidBody.Position + Physics.Gravity.Normalized);
|
||||
Vector3 groundDelta = Physics.Gravity.Normalized * (collisionMargin*2);
|
||||
TraceInfo traceGround = TracePlayer(position, position + groundDelta);
|
||||
|
||||
if (!traceGround.startSolid && traceGround.fraction < 1f &&
|
||||
-Vector3.Dot(Physics.Gravity.Normalized, traceGround.hitNormal) < 0.7f)
|
||||
{
|
||||
// slope
|
||||
// clip velocity
|
||||
Vector3 bounce = Physics.Gravity.Normalized;
|
||||
Vector3 bounce = groundDelta;
|
||||
//Vector3 velocityProjected = Vector3.ProjectOnPlane(velocity, normal);
|
||||
float backoff = Vector3.Dot(bounce, traceGround.hitNormal) * 2f;
|
||||
bounce -= traceGround.hitNormal * backoff;
|
||||
//velocity = velocityProjected;
|
||||
|
||||
Vector3 point = (rigidBody.Position + Physics.Gravity.Normalized) +
|
||||
Vector3 point = (position + groundDelta) +
|
||||
(1f - traceGround.fraction) * bounce;
|
||||
|
||||
// retrace
|
||||
traceGround = TracePlayer(rigidBody.Position, rigidBody.Position + point);
|
||||
traceGround = TracePlayer(position, position + point);
|
||||
}
|
||||
|
||||
if (!traceGround.startSolid && (traceGround.fraction >= 1f ||
|
||||
@@ -362,6 +634,37 @@ namespace Game
|
||||
onGround = !traceGround.startSolid;
|
||||
}
|
||||
|
||||
//onGround |= overlaps.Length > 0;
|
||||
|
||||
if (onGround && physicsInteractions && traceGround.hitInfos.Length > 0)
|
||||
{
|
||||
// apply resting force to rigid bodies under the player
|
||||
//bool collided = false;
|
||||
foreach (var hit in traceGround.hitInfos)
|
||||
{
|
||||
if (hit.Collider.AttachedRigidBody == null || hit.Collider.AttachedRigidBody.IsKinematic)
|
||||
continue;
|
||||
|
||||
if (hit.Distance <= 0f)
|
||||
continue;
|
||||
|
||||
//Console.Print(Physics.Gravity.Length.ToString());
|
||||
Vector3 force = -hit.Normal * (Physics.Gravity.Length) * rigidBody.Mass * Time.DeltaTime;
|
||||
hit.Collider.AttachedRigidBody.AddForceAtPosition(force, hit.Point, ForceMode.Impulse);
|
||||
//collided = true;
|
||||
//Console.Print("downforce: " + force.Length / Time.DeltaTime);
|
||||
}
|
||||
|
||||
//if (collided)
|
||||
// fraction = 1.0f; // finish movement and stop
|
||||
}
|
||||
|
||||
/*if (!onGround)
|
||||
Console.Print("air");
|
||||
else
|
||||
Console.Print("ground");*/
|
||||
|
||||
|
||||
/*if (onGround)
|
||||
{
|
||||
// snap to ground
|
||||
@@ -425,37 +728,37 @@ namespace Game
|
||||
{
|
||||
//jumped = true;
|
||||
|
||||
currentVelocity += Vector3.Up * jumpVelocity;
|
||||
velocity += Vector3.Up * jumpVelocity;
|
||||
onGround = false;
|
||||
}
|
||||
else if (jumped) // jump released
|
||||
jumped = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ground friction
|
||||
if (onGround)
|
||||
{
|
||||
float currentSpeed = currentVelocity.Length;
|
||||
float currentSpeed = velocity.Length;
|
||||
|
||||
float control = currentSpeed < stopspeed ? stopspeed : currentSpeed;
|
||||
var drop = control * friction * Time.DeltaTime;
|
||||
|
||||
|
||||
float newspeed = currentSpeed - drop;
|
||||
if (newspeed < 0)
|
||||
newspeed = 0;
|
||||
|
||||
if (currentSpeed < 0.0001f)
|
||||
currentVelocity *= 0;
|
||||
velocity *= 0;
|
||||
else
|
||||
currentVelocity *= newspeed / currentSpeed;
|
||||
velocity *= newspeed / currentSpeed;
|
||||
}
|
||||
|
||||
//bool stepUp = false;
|
||||
|
||||
|
||||
if (onGround) // ground acceleration
|
||||
{
|
||||
ApplyAcceleration(wishVelocity.Normalized, wishVelocity.Length, float.MaxValue, accelerationGround);
|
||||
ApplyAcceleration(ref velocity, wishVelocity.Normalized, wishVelocity.Length, float.MaxValue, accelerationGround);
|
||||
}
|
||||
else // air acceleration
|
||||
{
|
||||
@@ -464,39 +767,72 @@ namespace Game
|
||||
wishspeed = maxAirSpeed;
|
||||
|
||||
if (strafeAcceleration != 0f)
|
||||
ApplyAcceleration(wishVelocity.Normalized, wishspeed, maxAirStrafeSpeed, strafeAcceleration);
|
||||
ApplyAcceleration(ref velocity, wishVelocity.Normalized, wishspeed, maxAirStrafeSpeed, strafeAcceleration);
|
||||
|
||||
//stepUp = true;
|
||||
//stepUp = true;
|
||||
}
|
||||
|
||||
if (!onGround)
|
||||
{
|
||||
currentVelocity += Physics.Gravity * Time.DeltaTime;
|
||||
velocity += Physics.Gravity * Time.DeltaTime;
|
||||
//Console.Print("grav");
|
||||
}
|
||||
//else
|
||||
// Console.Print("Yv: " + currentVelocity.Y);
|
||||
|
||||
Vector3 newPosition = rigidBody.Position;
|
||||
SlideMove(ref newPosition, false, ref currentVelocity);
|
||||
|
||||
|
||||
|
||||
safePosition = rigidBody.Position;
|
||||
rigidBody.Position = newPosition;
|
||||
//if (currentVelocity.Length > 0.0f)
|
||||
// rigidBody.Position += currentVelocity * Time.DeltaTime;
|
||||
rigidBody.LinearVelocity = Vector3.Zero;
|
||||
currentVelocity = velocity;
|
||||
if (!rigidBody.IsKinematic)
|
||||
{
|
||||
//rigidBody.IsKinematic = false;
|
||||
//rigidBody.Position = position;
|
||||
rigidBody.LinearVelocity = velocity;
|
||||
//Console.Print("being pushed " + rigidBody.LinearVelocity.Length);
|
||||
//rigidBody.AddForce(velocity + ((position - rigidBody.Position) * Time.DeltaTime), ForceMode.Impulse);
|
||||
}
|
||||
else
|
||||
{
|
||||
SlideMove(ref position, false, ref velocity);
|
||||
|
||||
//rigidBody.IsKinematic = true;
|
||||
rigidBody.Position = position;
|
||||
rigidBody.LinearVelocity = velocity;
|
||||
}
|
||||
|
||||
/*if (proxyBody != null)
|
||||
{
|
||||
if (beingPushed)
|
||||
{
|
||||
//rigidBody.Position = proxyBody.Position;
|
||||
rigidBody.LinearVelocity = proxyBody.LinearVelocity;
|
||||
//rigidBody.Position += rigidBody.LinearVelocity * Time.DeltaTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
var proxyVelocity = position - proxyBody.Position;
|
||||
//proxyBody.LinearVelocity += proxyVelocity;
|
||||
//rigidBody.Position = proxyBody.Position;
|
||||
proxyBody.Position = position;
|
||||
proxyBody.LinearVelocity = velocity;
|
||||
}
|
||||
}*/
|
||||
|
||||
//rigidBody.LinearVelocity = velocity;
|
||||
|
||||
//if (currentVelocity.Length > 0.01f)
|
||||
// Console.Print("vel: " + currentVelocity.ToString());
|
||||
}
|
||||
|
||||
void ApplyAcceleration(Vector3 wishDir, float wishspeed, float maxWishspeed, float acceleration)
|
||||
void ApplyAcceleration(ref Vector3 velocity, Vector3 wishDir, float wishspeed, float maxWishspeed, float acceleration)
|
||||
{
|
||||
float wishspeedOrig = wishspeed;
|
||||
if (wishspeed > maxWishspeed)
|
||||
wishspeed = maxWishspeed;
|
||||
|
||||
float currentSpeed = Vector3.Dot(currentVelocity, wishDir);
|
||||
float currentSpeed = Vector3.Dot(velocity, wishDir);
|
||||
float addSpeed = wishspeed - currentSpeed;
|
||||
if (addSpeed <= 0f)
|
||||
return;
|
||||
@@ -505,7 +841,7 @@ namespace Game
|
||||
if (accelSpeed > addSpeed)
|
||||
accelSpeed = addSpeed;
|
||||
|
||||
currentVelocity += accelSpeed * wishDir;
|
||||
velocity += accelSpeed * wishDir;
|
||||
}
|
||||
|
||||
public override void OnUpdate()
|
||||
|
||||
762
Source/Game/PlayerMovement_NK.cs
Normal file
762
Source/Game/PlayerMovement_NK.cs
Normal file
@@ -0,0 +1,762 @@
|
||||
using System.Collections.Generic;
|
||||
using FlaxEngine;
|
||||
using Cabrito;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using FlaxEngine.Assertions;
|
||||
|
||||
namespace Game
|
||||
{
|
||||
public struct TraceInfo
|
||||
{
|
||||
public RayCastHit[] hitInfos;
|
||||
public bool startSolid;
|
||||
|
||||
// closest hit
|
||||
public float fraction;
|
||||
public Vector3 endPosition;
|
||||
public Vector3 hitNormal;
|
||||
public Vector3 hitPosition;
|
||||
|
||||
// furthest hit
|
||||
//public float maxFraction;
|
||||
//public Vector3 maxHitNormal;
|
||||
//public Vector3 maxEndPosition;
|
||||
}
|
||||
|
||||
public class PlayerMovement_NK : Script
|
||||
{
|
||||
[Limit(0, 9000), Tooltip("Base Movement speed")]
|
||||
public float MoveSpeed { get; set; } = 320;
|
||||
|
||||
private float viewPitch;
|
||||
private float viewYaw;
|
||||
private float viewRoll;
|
||||
|
||||
private InputEvent onExit = new InputEvent("Exit");
|
||||
|
||||
private const float collisionMargin = 0.031f * 1.666f;
|
||||
|
||||
Actor rootActor;
|
||||
public override void OnAwake()
|
||||
{
|
||||
base.OnAwake();
|
||||
|
||||
onExit.Triggered += () =>
|
||||
{
|
||||
if (Console.IsSafeToQuit)
|
||||
Engine.RequestExit();
|
||||
};
|
||||
|
||||
rootActor = Actor.GetChild(0);
|
||||
|
||||
RigidBody rigidBody = Actor.As<RigidBody>();
|
||||
rigidBody.CollisionEnter += OnCollisionEnter;
|
||||
rigidBody.CollisionExit += OnCollisionLeave;
|
||||
rigidBody.TriggerEnter += OnTriggerEnter;
|
||||
|
||||
//rigidBody.SetSolverIterationCounts(40, 10);
|
||||
|
||||
Console.Print("playermovement init: " + rigidBody.MaxDepenetrationVelocity.ToString());
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(PhysicsColliderActor colliderActor)
|
||||
{
|
||||
Console.Print("trogger: ");
|
||||
}
|
||||
|
||||
private void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
//Console.Print("collision: " + collision.Contacts[0].Normal);
|
||||
}
|
||||
|
||||
private void OnCollisionLeave(Collision collision)
|
||||
{
|
||||
//Console.Print("collision leave: " + collision.Contacts[0].Normal);
|
||||
}
|
||||
|
||||
public override void OnDestroy()
|
||||
{
|
||||
base.OnDestroy();
|
||||
|
||||
onExit.Dispose();
|
||||
}
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
var initialEulerAngles = Actor.Orientation.EulerAngles;
|
||||
viewPitch = initialEulerAngles.X;
|
||||
viewYaw = initialEulerAngles.Y;
|
||||
viewRoll = initialEulerAngles.Z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks for overlapping colliders in place using the player's rigidbody.
|
||||
/// </summary>
|
||||
/// <param name="position">Position</param>
|
||||
/// <returns></returns>
|
||||
private Collider[] TracePlayer(Vector3 position, float tolerance = 0.0f)
|
||||
{
|
||||
Collider[] colliders = null;
|
||||
|
||||
bool collided = false;
|
||||
var capsuleCollider = Actor.GetChild<CapsuleCollider>();
|
||||
var boxCollider = Actor.GetChild<BoxCollider>();
|
||||
var meshCollider = Actor.GetChild<MeshCollider>();
|
||||
PhysicsColliderActor colliderActor = null;
|
||||
if (capsuleCollider && capsuleCollider.IsActive)
|
||||
{
|
||||
colliderActor = capsuleCollider;
|
||||
collided = Physics.OverlapCapsule(position,
|
||||
capsuleCollider.Radius + tolerance, capsuleCollider.Height + tolerance,
|
||||
out colliders, capsuleCollider.Orientation,
|
||||
uint.MaxValue,
|
||||
false);
|
||||
}
|
||||
else if (meshCollider && meshCollider.IsActive)
|
||||
{
|
||||
colliderActor = meshCollider;
|
||||
collided = Physics.OverlapConvex(position,
|
||||
meshCollider.CollisionData, meshCollider.Scale + tolerance,
|
||||
out colliders, meshCollider.Orientation,
|
||||
uint.MaxValue,
|
||||
false);
|
||||
}
|
||||
else if (boxCollider && boxCollider.IsActive)
|
||||
{
|
||||
colliderActor = boxCollider;
|
||||
collided = Physics.OverlapBox(position,
|
||||
boxCollider.OrientedBox.Extents + tolerance,
|
||||
out colliders, boxCollider.Orientation,
|
||||
uint.MaxValue,
|
||||
false);
|
||||
}
|
||||
else
|
||||
Assert.Fail("No supported colliders found for rigidbody");
|
||||
|
||||
if (!collided)
|
||||
return colliders;
|
||||
|
||||
List<Collider> collidersFiltered = new List<Collider>();
|
||||
foreach (var collider in colliders)
|
||||
{
|
||||
if (collider == colliderActor)
|
||||
continue;
|
||||
|
||||
collidersFiltered.Add(collider);
|
||||
}
|
||||
|
||||
if (collidersFiltered.Count == 0)
|
||||
return colliders; // self-collision?
|
||||
|
||||
return collidersFiltered.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sweeps the player rigidbody in world and returns geometry which was hit during the trace.
|
||||
/// </summary>
|
||||
/// <param name="start">Start position</param>
|
||||
/// <param name="end">End position</param>
|
||||
/// <returns></returns>
|
||||
private TraceInfo TracePlayer(Vector3 start, Vector3 end, float tolerance = 0.0f)
|
||||
{
|
||||
TraceInfo traceInfo = new TraceInfo();
|
||||
|
||||
Vector3 delta = end - start;
|
||||
float maxDistance = delta.Length;
|
||||
Vector3 direction = delta.Normalized;
|
||||
|
||||
bool collided = false;
|
||||
var capsuleCollider = Actor.GetChild<CapsuleCollider>();
|
||||
var boxCollider = Actor.GetChild<BoxCollider>();
|
||||
var meshCollider = Actor.GetChild<MeshCollider>();
|
||||
PhysicsColliderActor colliderActor = null;
|
||||
if (capsuleCollider && capsuleCollider.IsActive)
|
||||
{
|
||||
colliderActor = capsuleCollider;
|
||||
collided = Physics.CapsuleCastAll(start,
|
||||
capsuleCollider.Radius + tolerance, capsuleCollider.Height,
|
||||
direction, out traceInfo.hitInfos, capsuleCollider.Orientation, maxDistance,
|
||||
uint.MaxValue,
|
||||
false);
|
||||
}
|
||||
else if (meshCollider && meshCollider.IsActive)
|
||||
{
|
||||
colliderActor = meshCollider;
|
||||
collided = Physics.ConvexCastAll(start,
|
||||
meshCollider.CollisionData, meshCollider.Scale + tolerance,
|
||||
direction, out traceInfo.hitInfos, meshCollider.Orientation, maxDistance,
|
||||
uint.MaxValue,
|
||||
false);
|
||||
}
|
||||
else if (boxCollider && boxCollider.IsActive)
|
||||
{
|
||||
colliderActor = boxCollider;
|
||||
collided = Physics.BoxCastAll(start,
|
||||
boxCollider.OrientedBox.Extents + tolerance,
|
||||
direction, out traceInfo.hitInfos, boxCollider.Orientation, maxDistance, uint.MaxValue,
|
||||
false);
|
||||
}
|
||||
|
||||
if (collided)
|
||||
{
|
||||
List<RayCastHit> hitInfosFiltered = new List<RayCastHit>();
|
||||
RayCastHit closest = new RayCastHit();
|
||||
closest.Distance = float.MaxValue;
|
||||
foreach (var hitInfo in traceInfo.hitInfos)
|
||||
{
|
||||
if (hitInfo.Collider == colliderActor)
|
||||
continue;
|
||||
|
||||
hitInfosFiltered.Add(hitInfo);
|
||||
|
||||
if (hitInfo.Distance < closest.Distance && hitInfo.Distance != 0.0f)
|
||||
closest = hitInfo;
|
||||
}
|
||||
|
||||
if (hitInfosFiltered.Count == 0)
|
||||
collided = false; // self-collision?
|
||||
else //if (closest.Distance > 0f)
|
||||
{
|
||||
if (closest.Distance == float.MaxValue)
|
||||
{
|
||||
foreach (var hitInfo in hitInfosFiltered)
|
||||
{
|
||||
if (hitInfo.Distance < closest.Distance)
|
||||
closest = hitInfo;
|
||||
}
|
||||
}
|
||||
|
||||
traceInfo.hitInfos = hitInfosFiltered.ToArray();
|
||||
|
||||
traceInfo.fraction = closest.Distance / maxDistance;
|
||||
traceInfo.hitNormal = closest.Normal;
|
||||
traceInfo.hitPosition = closest.Point;
|
||||
traceInfo.endPosition = start + (delta * traceInfo.fraction);
|
||||
|
||||
if (traceInfo.fraction == 0f && maxDistance > 0f)
|
||||
traceInfo.startSolid = true;
|
||||
}
|
||||
/*else
|
||||
{
|
||||
traceInfo.startSolid = true;
|
||||
traceInfo.fraction = 0f;
|
||||
}*/
|
||||
}
|
||||
|
||||
if (!collided)
|
||||
{
|
||||
traceInfo.hitInfos = new RayCastHit[0];
|
||||
traceInfo.fraction = 1f;
|
||||
traceInfo.endPosition = end;
|
||||
}
|
||||
|
||||
return traceInfo;
|
||||
}
|
||||
|
||||
public override void OnDebugDraw()
|
||||
{
|
||||
base.OnDebugDraw();
|
||||
|
||||
var capsuleCollider = Actor.GetChild<CapsuleCollider>();
|
||||
var boxCollider = Actor.GetChild<BoxCollider>();
|
||||
var meshCollider = Actor.GetChild<MeshCollider>();
|
||||
if (capsuleCollider && capsuleCollider.IsActive)
|
||||
{
|
||||
Quaternion rotation = capsuleCollider.LocalOrientation * Quaternion.Euler(0f, 90f, 0f);
|
||||
DebugDraw.DrawWireTube(capsuleCollider.Position, rotation, capsuleCollider.Radius, capsuleCollider.Height, Color.GreenYellow * 0.8f);
|
||||
}
|
||||
else if (meshCollider && meshCollider.IsActive)
|
||||
{
|
||||
//Quaternion rotation = meshCollider.LocalOrientation * Quaternion.Euler(0f, 90f, 0f);
|
||||
DebugDraw.DrawWireCylinder(meshCollider.Position, meshCollider.Orientation, capsuleCollider.Radius, capsuleCollider.Height + capsuleCollider.Radius * 2, Color.GreenYellow * 0.8f);
|
||||
//DebugDraw.DrawWireTube(meshCollider.Position, rotation, meshCollider.Radius, meshCollider.Height, Color.GreenYellow * 0.8f);
|
||||
}
|
||||
else if (boxCollider && boxCollider.IsActive)
|
||||
{
|
||||
DebugDraw.DrawWireBox(boxCollider.OrientedBox.GetBoundingBox(), Color.GreenYellow * 0.8f);
|
||||
}
|
||||
}
|
||||
|
||||
private void SlideMove(ref Vector3 position, bool stepUp, ref Vector3 velocity, bool asdf = false)
|
||||
{
|
||||
if (velocity.IsZero)
|
||||
return;
|
||||
|
||||
Vector3 originalPosition = position;
|
||||
Vector3 originalVelocity = velocity;
|
||||
|
||||
float timeleft = Time.DeltaTime;
|
||||
|
||||
List<Vector3> hitNormals = new List<Vector3>();
|
||||
|
||||
for (int bump = 0; bump < 4; bump++)
|
||||
{
|
||||
Vector3 startPos = position;
|
||||
Vector3 endPos = position + (velocity * timeleft);
|
||||
|
||||
TraceInfo trace = TracePlayer(startPos, endPos);
|
||||
// TODO: handle portals here
|
||||
|
||||
float fraction = trace.fraction;
|
||||
Vector3 hitNormal = trace.hitNormal;
|
||||
|
||||
if (trace.startSolid)
|
||||
{
|
||||
velocity = Vector3.Zero;
|
||||
break;
|
||||
}
|
||||
|
||||
if (physicsInteractions)
|
||||
{
|
||||
RigidBody rigidBody = Actor.As<RigidBody>();
|
||||
foreach (var hit in trace.hitInfos)
|
||||
{
|
||||
if (hit.Collider.AttachedRigidBody == null || hit.Collider.AttachedRigidBody.IsKinematic)
|
||||
continue;
|
||||
|
||||
Vector3 force = -hit.Normal * velocity.Length * rigidBody.Mass;
|
||||
//Console.Print("move force: " + (force.Length / timeleft));
|
||||
hit.Collider.AttachedRigidBody.AddForce(force, ForceMode.Force);
|
||||
}
|
||||
}
|
||||
|
||||
if (fraction > 0f)
|
||||
{
|
||||
position = trace.endPosition;
|
||||
hitNormals.Clear(); // this is present in some forks, not in Q3
|
||||
}
|
||||
|
||||
if (fraction >= 1f)
|
||||
break;
|
||||
|
||||
timeleft *= 1.0f - fraction;
|
||||
|
||||
// this doesn't seem to do anything, we never have any hitNormals stored here
|
||||
bool hitPreviousNormal = false;
|
||||
foreach (Vector3 normal in hitNormals)
|
||||
{
|
||||
if (Vector3.Dot(hitNormal, normal) > 0.99)
|
||||
{
|
||||
// nudge away from the same wall we hit earlier and try again
|
||||
velocity += hitNormal;
|
||||
hitPreviousNormal = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hitPreviousNormal)
|
||||
continue;
|
||||
|
||||
hitNormals.Add(hitNormal);
|
||||
if (hitNormals.Count != 1)
|
||||
Console.Print("hitNormals: " + hitNormals.Count);
|
||||
|
||||
int plane;
|
||||
Vector3 normalMargin = Vector3.Zero;
|
||||
for (plane = 0; plane < hitNormals.Count; plane++)
|
||||
{
|
||||
Vector3 normal = hitNormals[plane];
|
||||
|
||||
// clip velocity
|
||||
velocity -= normal * Vector3.Dot(velocity, normal);
|
||||
//velocity = Vector3.ProjectOnPlane(velocity, normal);
|
||||
|
||||
//traceOffset = normal * 1f;
|
||||
normalMargin += normal;
|
||||
//position += normal * 0.031f;
|
||||
|
||||
int plane2;
|
||||
for (plane2 = 0; plane2 < hitNormals.Count; plane2++)
|
||||
{
|
||||
if (plane == plane2)
|
||||
continue;
|
||||
|
||||
if (Vector3.Dot(velocity, hitNormals[plane2]) < 0f)
|
||||
break;
|
||||
}
|
||||
|
||||
if (plane2 == hitNormals.Count)
|
||||
break;
|
||||
}
|
||||
|
||||
// push off slightly away from the walls to not get stuck
|
||||
position += normalMargin.Normalized * collisionMargin;
|
||||
|
||||
if (plane == hitNormals.Count)
|
||||
{
|
||||
if (hitNormals.Count == 2)
|
||||
{
|
||||
Vector3 dir = Vector3.Cross(hitNormals[0], hitNormals[1]);
|
||||
//dir.Normalize();
|
||||
float dist = Vector3.Dot(dir, velocity);
|
||||
velocity = dist * dir;
|
||||
}
|
||||
else
|
||||
{
|
||||
velocity = Vector3.Zero;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// nudge very slightly away from the wall to avoid getting stuck
|
||||
//position += trace.hitNormal * 0.01f;
|
||||
//velocity += trace.hitNormal * 0.01f;
|
||||
}
|
||||
|
||||
// prevents bouncing against the wall
|
||||
if (/*velocity.Length > 0f && */Vector3.Dot(velocity, originalVelocity) <= 0f)
|
||||
{
|
||||
velocity = Vector3.Zero;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Vector3 wishVelocity = Vector3.Zero;
|
||||
//Vector3 gravityVelocity = Vector3.Zero;
|
||||
//Vector3 currentVelocity = Vector3.Zero;
|
||||
private bool onGround = false;
|
||||
|
||||
private const float friction = 4f;
|
||||
private const float stopspeed = 100f;
|
||||
private const float accelerationGround = 10f;
|
||||
private const float jumpVelocity = 270f;
|
||||
|
||||
private const float maxAirSpeed = 320f;
|
||||
private const float maxAirStrafeSpeed = 30f; //Q2+
|
||||
private const float airAcceleration = 0.4f * 0f; //Q2+
|
||||
private const float airStopAcceleration = 2.5f * 0f; //Q2+
|
||||
private const float airStrafeAcceleration = 70f * 0f; //CPM?
|
||||
private const float strafeAcceleration = 10f; //QW
|
||||
private const float airControl = 0f; //CPM
|
||||
private bool physicsInteractions = false;
|
||||
|
||||
private bool jumped = false;
|
||||
|
||||
private Vector3 safePosition;
|
||||
private Vector3 currentVelocity;
|
||||
|
||||
|
||||
|
||||
public override void OnFixedUpdate()
|
||||
{
|
||||
RigidBody rigidBody = Actor.As<RigidBody>();
|
||||
Transform rootTrans = rootActor.Transform;
|
||||
|
||||
Vector3 inputDirection = new Vector3(InputManager.GetAxis("Horizontal"), 0.0f, InputManager.GetAxis("Vertical"));
|
||||
Vector3 moveDirection = rootTrans.TransformDirection(inputDirection);
|
||||
|
||||
//Vector3 position = rigidBody.Position;
|
||||
Vector3 velocity = rigidBody.LinearVelocity;//currentVelocity;
|
||||
|
||||
Vector3 wishVelocity = Vector3.Zero;
|
||||
if (!inputDirection.IsZero)
|
||||
wishVelocity = moveDirection.Normalized * MoveSpeed;
|
||||
|
||||
// categorize position
|
||||
onGround = true;
|
||||
Vector3 groundDelta = Physics.Gravity.Normalized * collisionMargin*2;
|
||||
Vector3 traceGroundStart = rigidBody.Position - groundDelta;
|
||||
Vector3 traceGroundEnd = rigidBody.Position + groundDelta;
|
||||
TraceInfo traceGround = TracePlayer(traceGroundStart, traceGroundEnd, -0.1f);
|
||||
|
||||
float groundDistance = 0.1f;
|
||||
|
||||
if (traceGround.fraction < 1f/* && !traceGround.startSolid*//*&& ddot < 0.7f*/)
|
||||
{
|
||||
|
||||
/*
|
||||
// slope
|
||||
// clip velocity
|
||||
Vector3 bounce = -groundDelta;
|
||||
Vector3 bounceDir = -groundDelta.Normalized;//traceGround.hitNormal;
|
||||
//Vector3 velocityProjected = Vector3.ProjectOnPlane(velocity, normal);
|
||||
float backoff = Vector3.Dot(bounce, bounceDir) * 2f;
|
||||
bounce -= bounceDir * backoff;
|
||||
//velocity = velocityProjected;
|
||||
|
||||
Vector3 point = (rigidBody.Position + groundDelta) +
|
||||
(1f - traceGround.fraction) * bounce;
|
||||
//Vector3 point = rigidBody.Position - ((1f - traceGround.fraction) * groundDelta);
|
||||
|
||||
//rigidBody.Position = point;
|
||||
// retrace
|
||||
//traceGround = TracePlayer(traceGround.endPosition, point);
|
||||
*/
|
||||
}
|
||||
|
||||
/*if (!traceGround.startSolid && traceGround.fraction < 1f &&
|
||||
-Vector3.Dot(Physics.Gravity.Normalized, traceGround.hitNormal) < 0.7f)
|
||||
{
|
||||
// slope
|
||||
// clip velocity
|
||||
Vector3 bounce = groundDelta;
|
||||
//Vector3 velocityProjected = Vector3.ProjectOnPlane(velocity, normal);
|
||||
float backoff = Vector3.Dot(bounce, traceGround.hitNormal) * 2f;
|
||||
bounce -= traceGround.hitNormal * backoff;
|
||||
//velocity = velocityProjected;
|
||||
|
||||
Vector3 point = (rigidBody.Position + groundDelta) +
|
||||
(1f - traceGround.fraction) * bounce;
|
||||
|
||||
// retrace
|
||||
traceGround = TracePlayer(rigidBody.Position, rigidBody.Position + point);
|
||||
}*/
|
||||
|
||||
//if (!traceGround.startSolid && (traceGround.fraction >= 1f ||
|
||||
// -Vector3.Dot(Physics.Gravity.Normalized, traceGround.hitNormal) < 0.7f))
|
||||
|
||||
float rampDot = -Vector3.Dot(Physics.Gravity.Normalized, traceGround.hitNormal);
|
||||
if (traceGround.fraction >= 1f)
|
||||
rampDot = 1f;
|
||||
else if (traceGround.hitNormal.IsZero)
|
||||
rampDot = 99f;
|
||||
|
||||
if (traceGround.fraction >= 1f || rampDot < 0.7f)
|
||||
{
|
||||
//Console.Print("air: " + (-Vector3.Dot(Physics.Gravity.Normalized, traceGround.hitNormal)).ToString());
|
||||
// falling or sliding down a slope
|
||||
onGround = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
float closestDist = float.MaxValue;
|
||||
foreach (var hit in traceGround.hitInfos)
|
||||
{
|
||||
if (hit.Distance < closestDist && hit.Distance != 0f)
|
||||
closestDist = hit.Distance;
|
||||
}
|
||||
|
||||
if (traceGround.fraction == 0f && closestDist != 0f)
|
||||
Console.Print("minteresting");
|
||||
//Console.Print("grund: "+ (-Vector3.Dot(Physics.Gravity.Normalized, traceGround.hitNormal)).ToString());
|
||||
onGround = true;//!traceGround.startSolid;
|
||||
//velocity.Y = 0f;
|
||||
|
||||
// move slightly above the ground
|
||||
// maintain distance off the ground
|
||||
float dist = ((traceGroundEnd - rigidBody.Position) * (traceGround.fraction - 0.5f)).Length;
|
||||
|
||||
if (dist < groundDistance)
|
||||
{
|
||||
var newPos = rigidBody.Position;
|
||||
newPos.Y += groundDistance - dist;
|
||||
//rigidBody.Position = newPos;
|
||||
//velocity.Y = 0f;
|
||||
}
|
||||
//velocity.Y = 0f;
|
||||
}
|
||||
|
||||
onGround = true;
|
||||
//Console.Print("frac: " + traceGround.fraction + "norm: " + rampDot);
|
||||
|
||||
|
||||
|
||||
|
||||
//onGround |= overlaps.Length > 0;
|
||||
|
||||
/*if (onGround && physicsInteractions && traceGround.hitInfos.Length > 0)
|
||||
{
|
||||
// apply resting force to rigid bodies under the player
|
||||
//bool collided = false;
|
||||
foreach (var hit in traceGround.hitInfos)
|
||||
{
|
||||
if (hit.Collider.AttachedRigidBody == null || hit.Collider.AttachedRigidBody.IsKinematic)
|
||||
continue;
|
||||
|
||||
if (hit.Distance <= 0f)
|
||||
continue;
|
||||
|
||||
//Console.Print(Physics.Gravity.Length.ToString());
|
||||
Vector3 force = -hit.Normal * (Physics.Gravity.Length) * rigidBody.Mass * Time.DeltaTime;
|
||||
hit.Collider.AttachedRigidBody.AddForceAtPosition(force, hit.Point, ForceMode.Impulse);
|
||||
//collided = true;
|
||||
//Console.Print("downforce: " + force.Length / Time.DeltaTime);
|
||||
}
|
||||
|
||||
//if (collided)
|
||||
// fraction = 1.0f; // finish movement and stop
|
||||
}*/
|
||||
|
||||
/*if (!onGround)
|
||||
Console.Print("air");
|
||||
else
|
||||
Console.Print("ground");*/
|
||||
|
||||
|
||||
/*if (onGround)
|
||||
{
|
||||
// snap to ground
|
||||
if (!traceGround.startSolid)
|
||||
{
|
||||
Vector3 newPos = rigidBody.Position;
|
||||
|
||||
if (traceGround.fraction < 1f)
|
||||
{
|
||||
//newPos += -Physics.Gravity.Normalized * traceGround.fraction;
|
||||
}
|
||||
rigidBody.Position = newPos;
|
||||
}
|
||||
}*/
|
||||
/*if (traceGround.startSolid)
|
||||
{
|
||||
Console.Print("stuk: ");
|
||||
|
||||
rigidBody.Position = safePosition;
|
||||
|
||||
traceGround = TracePlayer(rigidBody.Position, rigidBody.Position + Physics.Gravity.Normalized,
|
||||
false);
|
||||
|
||||
//onGround = true;
|
||||
|
||||
//currentVelocity.Y = 0f;
|
||||
}
|
||||
|
||||
if (!traceGround.startSolid)
|
||||
{
|
||||
foreach (var hitInfo in traceGround.hitInfos)
|
||||
{
|
||||
var dot = Vector3.Dot(Physics.Gravity.Normalized, hitInfo.Normal);
|
||||
if (-dot >= 0.7) //~45deg slope
|
||||
{
|
||||
//Console.Print("d: " + hitInfo.Distance);
|
||||
Vector3 newPos = rigidBody.Position;
|
||||
|
||||
if (hitInfo.Distance > 0f)
|
||||
newPos += Physics.Gravity.Normalized * (hitInfo.Distance - 0.01f);
|
||||
else
|
||||
newPos += hitInfo.Normal * 0.1f;
|
||||
|
||||
rigidBody.Position = newPos;
|
||||
|
||||
onGround = true;
|
||||
currentVelocity.Y = 0f;
|
||||
break;
|
||||
|
||||
//if (currentVelocity.Length > 0.01f)
|
||||
// Console.Print("groundvel: " + currentVelocity.ToString());
|
||||
//currentVelocity.Y = 0.0f;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
// jump
|
||||
if (onGround)
|
||||
{
|
||||
if (!jumped && InputManager.GetAction("Jump"))
|
||||
{
|
||||
jumped = true;
|
||||
|
||||
velocity += Vector3.Up * jumpVelocity;
|
||||
onGround = false;
|
||||
}
|
||||
}
|
||||
if (jumped && !InputManager.GetAction("Jump")) // jump released
|
||||
jumped = false;
|
||||
|
||||
|
||||
// ground friction
|
||||
if (onGround)
|
||||
{
|
||||
float currentSpeed = velocity.Length;
|
||||
|
||||
float control = currentSpeed < stopspeed ? stopspeed : currentSpeed;
|
||||
var drop = control * friction * Time.DeltaTime;
|
||||
|
||||
float newspeed = currentSpeed - drop;
|
||||
if (newspeed < 0)
|
||||
newspeed = 0;
|
||||
|
||||
if (currentSpeed < 0.0001f)
|
||||
velocity *= 0;
|
||||
else
|
||||
velocity *= newspeed / currentSpeed;
|
||||
}
|
||||
|
||||
//bool stepUp = false;
|
||||
|
||||
if (onGround) // ground acceleration
|
||||
{
|
||||
ApplyAcceleration(ref velocity, wishVelocity.Normalized, wishVelocity.Length, float.MaxValue, accelerationGround);
|
||||
}
|
||||
else // air acceleration
|
||||
{
|
||||
var wishspeed = wishVelocity.Length;
|
||||
if (wishspeed > maxAirSpeed)
|
||||
wishspeed = maxAirSpeed;
|
||||
|
||||
if (strafeAcceleration != 0f)
|
||||
ApplyAcceleration(ref velocity, wishVelocity.Normalized, wishspeed, maxAirStrafeSpeed, strafeAcceleration);
|
||||
|
||||
//stepUp = true;
|
||||
}
|
||||
|
||||
if (!onGround)
|
||||
{
|
||||
velocity += Physics.Gravity * Time.DeltaTime;
|
||||
//Console.Print("grav");
|
||||
}
|
||||
//else
|
||||
// Console.Print("Yv: " + currentVelocity.Y);
|
||||
|
||||
//SlideMove(ref position, false, ref velocity);
|
||||
|
||||
safePosition = rigidBody.Position;
|
||||
if (rigidBody.EnableSimulation)
|
||||
{
|
||||
//rigidBody.Position = position;
|
||||
//Vector3 force = velocity - rigidBody.LinearVelocity;
|
||||
rigidBody.LinearVelocity = velocity;
|
||||
//rigidBody.AddForce(force, ForceMode.Impulse);
|
||||
}
|
||||
else
|
||||
{
|
||||
//rigidBody.Position = position;
|
||||
rigidBody.LinearVelocity = velocity;
|
||||
}
|
||||
|
||||
//rigidBody.LinearVelocity = velocity;
|
||||
|
||||
//if (currentVelocity.Length > 0.01f)
|
||||
// Console.Print("vel: " + currentVelocity.ToString());
|
||||
}
|
||||
|
||||
void ApplyAcceleration(ref Vector3 velocity, Vector3 wishDir, float wishspeed, float maxWishspeed, float acceleration)
|
||||
{
|
||||
float wishspeedOrig = wishspeed;
|
||||
if (wishspeed > maxWishspeed)
|
||||
wishspeed = maxWishspeed;
|
||||
|
||||
float currentSpeed = Vector3.Dot(velocity, wishDir);
|
||||
float addSpeed = wishspeed - currentSpeed;
|
||||
if (addSpeed <= 0f)
|
||||
return;
|
||||
|
||||
float accelSpeed = acceleration * wishspeedOrig * Time.DeltaTime;
|
||||
if (accelSpeed > addSpeed)
|
||||
accelSpeed = addSpeed;
|
||||
|
||||
velocity += accelSpeed * wishDir;
|
||||
}
|
||||
|
||||
public override void OnUpdate()
|
||||
{
|
||||
float xAxis = InputManager.GetAxisRaw("Mouse X");
|
||||
float yAxis = InputManager.GetAxisRaw("Mouse Y");
|
||||
if (xAxis != 0.0f || yAxis != 0.0f)
|
||||
{
|
||||
var camera = rootActor.GetChild<Camera>();
|
||||
|
||||
viewPitch += yAxis;
|
||||
viewYaw += xAxis;
|
||||
|
||||
viewPitch = Mathf.Clamp(viewPitch, -90.0f, 90.0f);
|
||||
|
||||
// root orientation must be set first
|
||||
rootActor.Orientation = Quaternion.Euler(0, viewYaw, 0);
|
||||
camera.Orientation = Quaternion.Euler(viewPitch, viewYaw, viewRoll);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user