wip movement stuff
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"ID": "0733cc9b40d3d05366be64bbd9b59e21",
|
||||
"TypeName": "FlaxEngine.SceneAsset",
|
||||
"EngineBuild": 6216,
|
||||
"EngineBuild": 6217,
|
||||
"Data": [
|
||||
{
|
||||
"ID": "0733cc9b40d3d05366be64bbd9b59e21",
|
||||
@@ -24,44 +24,6 @@
|
||||
"Quality": 100
|
||||
}
|
||||
},
|
||||
{
|
||||
"ID": "a092422548695989fdb8eeb8bc89eacb",
|
||||
"TypeName": "FlaxEngine.UICanvas",
|
||||
"ParentID": "0733cc9b40d3d05366be64bbd9b59e21",
|
||||
"Name": "ConsoleUICanvas",
|
||||
"Transform": {
|
||||
"Orientation": {
|
||||
"X": 1.0,
|
||||
"Y": 4.371138828673793e-8,
|
||||
"Z": 4.371138828673793e-8,
|
||||
"W": 1.910685465164705e-15
|
||||
}
|
||||
},
|
||||
"V": {
|
||||
"Order": -999999999,
|
||||
"Size": {
|
||||
"X": 1401.0,
|
||||
"Y": 813.0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"ID": "b165319d47550ff115d2e1ae9d9f95e5",
|
||||
"TypeName": "Cabrito.ConsoleScript",
|
||||
"ParentID": "a092422548695989fdb8eeb8bc89eacb",
|
||||
"V": {
|
||||
"ConsoleHeight": 0.635,
|
||||
"ConsoleFont": "43f32bec443158643f53699f07b2e09c",
|
||||
"BackgroundTexture": "16a2d3f1465e834c8ac965bd072c1dca",
|
||||
"BackgroundColor": {
|
||||
"R": 0.0,
|
||||
"G": 0.0,
|
||||
"B": 0.0,
|
||||
"A": 1.0
|
||||
},
|
||||
"LineSpacing": 1.0
|
||||
}
|
||||
},
|
||||
{
|
||||
"ID": "4ef1f38b4569142b55b0ff935525d47a",
|
||||
"TypeName": "FlaxEngine.RigidBody",
|
||||
@@ -78,6 +40,7 @@
|
||||
"LinearDamping": 0.0,
|
||||
"AngularDamping": 0.0,
|
||||
"Constraints": 56,
|
||||
"IsKinematic": true,
|
||||
"EnableGravity": false
|
||||
},
|
||||
{
|
||||
@@ -136,12 +99,7 @@
|
||||
"W": 1.910685465164705e-15
|
||||
}
|
||||
},
|
||||
"V": {
|
||||
"Size": {
|
||||
"X": 1401.0,
|
||||
"Y": 813.0
|
||||
}
|
||||
}
|
||||
"V": {}
|
||||
},
|
||||
{
|
||||
"ID": "f8ac0e55467d78743a7405a1d5720557",
|
||||
@@ -149,6 +107,20 @@
|
||||
"ParentID": "b5d566374477944e69bdc2b86249883b",
|
||||
"V": {
|
||||
"control": "17f6e00f48bbc783fc655a8be5bf12d2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"ID": "2297474f4c06db4d6110979976177b2d",
|
||||
"TypeName": "Cabrito.ConsoleScript",
|
||||
"ParentID": "b5d566374477944e69bdc2b86249883b",
|
||||
"V": {
|
||||
"ConsoleFont": "ec3a34464c0c59c40c52a29f469f161f",
|
||||
"BackgroundColor": {
|
||||
"R": 0.0,
|
||||
"G": 0.0,
|
||||
"B": 0.0,
|
||||
"A": 1.0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -165,7 +137,7 @@
|
||||
},
|
||||
"Control": "FlaxEngine.GUI.Label",
|
||||
"Data": {
|
||||
"Text": "FPS: 767\nrFPS: 767\nCon: NaNms\nDirectX11\nGC memory: 7.908752MB",
|
||||
"Text": "FPS: 14\nrFPS: 13\nCon: NaNms\nDirectX11\nGC memory: 15.89691MB",
|
||||
"TextColor": {
|
||||
"R": 1.0,
|
||||
"G": 1.0,
|
||||
@@ -178,8 +150,8 @@
|
||||
"B": 1.0,
|
||||
"A": 1.0
|
||||
},
|
||||
"HorizontalAlignment": 1,
|
||||
"VerticalAlignment": 1,
|
||||
"HorizontalAlignment": 0,
|
||||
"VerticalAlignment": 0,
|
||||
"Wrapping": 0,
|
||||
"Font": {
|
||||
"Font": "4508d98f4aa1f0bd59362b81d47e38f4",
|
||||
|
||||
45
Content/Settings/ConsoleUiCanvasPrefab.prefab
Normal file
45
Content/Settings/ConsoleUiCanvasPrefab.prefab
Normal file
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"ID": "327f82d44b3114035981f68c3ad0f793",
|
||||
"TypeName": "FlaxEngine.Prefab",
|
||||
"EngineBuild": 6216,
|
||||
"Data": [
|
||||
{
|
||||
"ID": "b2779da2451cf5ce88400d8663df4963",
|
||||
"TypeName": "FlaxEngine.UICanvas",
|
||||
"ParentID": "00000000000000000000000000000000",
|
||||
"Name": "ConsoleUICanvas",
|
||||
"Transform": {
|
||||
"Orientation": {
|
||||
"X": 1.0,
|
||||
"Y": 4.3711388286737938e-8,
|
||||
"Z": 4.3711388286737938e-8,
|
||||
"W": 1.910685465164705e-15
|
||||
}
|
||||
},
|
||||
"V": {
|
||||
"Order": -999999999,
|
||||
"Size": {
|
||||
"X": 1456.0,
|
||||
"Y": 813.0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"ID": "13d32654469ac6b38052ff937edbe9a0",
|
||||
"TypeName": "Cabrito.ConsoleScript",
|
||||
"ParentID": "b2779da2451cf5ce88400d8663df4963",
|
||||
"V": {
|
||||
"ConsoleHeight": 0.635,
|
||||
"ConsoleFont": "43f32bec443158643f53699f07b2e09c",
|
||||
"BackgroundTexture": "16a2d3f1465e834c8ac965bd072c1dca",
|
||||
"BackgroundColor": {
|
||||
"R": 0.0,
|
||||
"G": 0.0,
|
||||
"B": 0.0,
|
||||
"A": 1.0
|
||||
},
|
||||
"LineSpacing": 1.0
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -45,12 +45,10 @@ namespace Game
|
||||
viewRoll = initialEulerAngles.Z;
|
||||
}
|
||||
|
||||
Vector3 wishVelocity = new Vector3(0);
|
||||
//Vector3 wishVelocity = Vector3.Zero;
|
||||
Vector3 gravityVelocity = Vector3.Zero;
|
||||
public override void OnFixedUpdate()
|
||||
{
|
||||
if (Console.IsOpen)
|
||||
return;
|
||||
|
||||
var camera = rootActor.GetChild<Camera>();
|
||||
var camTrans = camera.Transform;
|
||||
var rootTrans = rootActor.Transform;
|
||||
@@ -61,33 +59,101 @@ namespace Game
|
||||
|
||||
var rigidBody = Actor.As<RigidBody>();
|
||||
|
||||
const float groundAccel = 30 * 100f;
|
||||
//const float groundDamping = 30f * 100;
|
||||
var moveDirection = rootTrans.TransformDirection(move);
|
||||
|
||||
Vector3 accel = new Vector3(0);
|
||||
|
||||
if (!move.IsZero)
|
||||
Vector3 wishVelocity = Vector3.Zero;
|
||||
if (!Console.IsOpen && !move.IsZero)
|
||||
{
|
||||
move.Normalize();
|
||||
|
||||
move = rootTrans.TransformDirection(move) * 10;
|
||||
move = moveDirection.Normalized * MoveSpeed * Time.DeltaTime / (1.0f/Time.PhysicsFPS);
|
||||
wishVelocity = move;
|
||||
|
||||
accel = move;
|
||||
|
||||
var groundVelocity = rigidBody.LinearVelocity;
|
||||
groundVelocity.Y = 0;
|
||||
|
||||
if (groundVelocity.Length > MoveSpeed)
|
||||
accel = new Vector3(0);
|
||||
/*var groundVelocity = rigidBody.LinearVelocity;
|
||||
groundVelocity.Y = 0f;
|
||||
if (groundVelocity.Length > 320)
|
||||
wishVelocity = wishVelocity.Normalized * 320;*/
|
||||
//wishVelocity = move;
|
||||
}
|
||||
/*else if (!wishVelocity.IsZero)
|
||||
{
|
||||
moveDirection = wishVelocity.Normalized;
|
||||
wishVelocity -= moveDirection * groundDamping * Time.DeltaTime;
|
||||
if (Vector3.Dot(wishVelocity, moveDirection) < 0)
|
||||
wishVelocity = Vector3.Zero;
|
||||
}*/
|
||||
//else if (!wishVelocity.IsZero)
|
||||
// wishVelocity = new Vector3(0);
|
||||
|
||||
//rigidBody.Position += wishVelocity * Time.DeltaTime;
|
||||
//rigidBody.AddForce(accel, ForceMode.Acceleration);
|
||||
rigidBody.LinearVelocity += accel;
|
||||
//rigidBody.LinearVelocity = wishVelocity;
|
||||
//rigidBody.LinearVelocity /= Time.DeltaTime;
|
||||
|
||||
var capsuleCollider = Actor.GetChild<CapsuleCollider>();
|
||||
|
||||
Vector3 velocity = wishVelocity;
|
||||
|
||||
bool collided = Physics.BoxCastAll(rigidBody.Position, new Vector3(capsuleCollider.Radius, (capsuleCollider.Height + capsuleCollider.Radius) / 2, capsuleCollider.Radius), Physics.Gravity.Normalized, out RayCastHit[] hitInfos, Quaternion.Identity, Physics.Gravity.Length * Time.DeltaTime, uint.MaxValue, false);
|
||||
|
||||
const float minDistanceFromFloor = 0.1f;
|
||||
|
||||
Vector3 floorNormal = Vector3.Zero;
|
||||
Vector3 floorPosition = Vector3.Zero;
|
||||
float floorDistance = 0.0f;
|
||||
if (collided)
|
||||
{
|
||||
collided = false;
|
||||
foreach (var hitInfo in hitInfos)
|
||||
{
|
||||
if (hitInfo.Collider == capsuleCollider)
|
||||
continue;
|
||||
|
||||
//if (hitInfo.Distance < minDistanceFromFloor)
|
||||
// continue;
|
||||
|
||||
collided = true;
|
||||
floorNormal = hitInfo.Normal;
|
||||
floorPosition = hitInfo.Point;
|
||||
floorDistance = hitInfo.Distance;
|
||||
//Console.Print("collided " + hitInfo.Distance.ToString());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!collided)
|
||||
gravityVelocity += Physics.Gravity * Time.DeltaTime;
|
||||
else
|
||||
{
|
||||
gravityVelocity = Vector3.Zero;
|
||||
|
||||
// if (floorDistance < minDistanceFromFloor)
|
||||
{
|
||||
var pos = rigidBody.Position;
|
||||
pos.Y = floorPosition.Y + (capsuleCollider.Height * 0.5f + capsuleCollider.Radius) + (minDistanceFromFloor * 0.5f);
|
||||
rigidBody.Position = pos;
|
||||
}
|
||||
|
||||
/*if (floorDistance < minDistanceFromFloor)
|
||||
{
|
||||
Console.Print("grav ");
|
||||
rigidBody.Position = new Vector3(rigidBody.Position.X, (floorPosition + (floorNormal * minDistanceFromFloor*0.9f)).Y, rigidBody.Position.Z);
|
||||
}*/
|
||||
//rigidBody.Position = floorPosition + (floorNormal * minDistanceFromFloor);
|
||||
}
|
||||
|
||||
Vector3 newVelocity = velocity + gravityVelocity;
|
||||
|
||||
if (newVelocity != rigidBody.LinearVelocity)
|
||||
rigidBody.LinearVelocity = newVelocity;
|
||||
|
||||
if (rigidBody.IsKinematic && !rigidBody.LinearVelocity.IsZero)
|
||||
rigidBody.Position += rigidBody.LinearVelocity * Time.DeltaTime;
|
||||
/*
|
||||
- check gravity
|
||||
- get normal for slope
|
||||
|
||||
moveVelocity = wishVelocity
|
||||
|
||||
|
||||
LinearVelocity = moveVelocity + _jumpVelocity + _gravityVelocity
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
public override void OnUpdate()
|
||||
|
||||
Reference in New Issue
Block a user