Reuse client mechanism for movement on entities
Also brings in some MonoGame math classes to fulfill this purpose.
This commit is contained in:
parent
9de14e371b
commit
4dd67d30fa
1663
TrueCraft.API/Matrix.cs
Normal file
1663
TrueCraft.API/Matrix.cs
Normal file
File diff suppressed because it is too large
Load Diff
@ -126,6 +126,7 @@
|
|||||||
<Compile Include="Logic\ISmeltableItem.cs" />
|
<Compile Include="Logic\ISmeltableItem.cs" />
|
||||||
<Compile Include="Logic\IBurnableItem.cs" />
|
<Compile Include="Logic\IBurnableItem.cs" />
|
||||||
<Compile Include="Logic\SoundEffectClass.cs" />
|
<Compile Include="Logic\SoundEffectClass.cs" />
|
||||||
|
<Compile Include="Matrix.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<ItemGroup />
|
<ItemGroup />
|
||||||
|
@ -111,6 +111,14 @@ namespace TrueCraft.API
|
|||||||
Square(other.Z - Z));
|
Square(other.Z - Z));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Vector3 Transform(Matrix matrix)
|
||||||
|
{
|
||||||
|
var x = (X * matrix.M11) + (Y * matrix.M21) + (Z * matrix.M31) + matrix.M41;
|
||||||
|
var y = (X * matrix.M12) + (Y * matrix.M22) + (Z * matrix.M32) + matrix.M42;
|
||||||
|
var z = (X * matrix.M13) + (Y * matrix.M23) + (Z * matrix.M33) + matrix.M43;
|
||||||
|
return new Vector3(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Calculates the square of a num.
|
/// Calculates the square of a num.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -3,6 +3,7 @@ using Microsoft.Xna.Framework.Graphics;
|
|||||||
using TrueCraft.API;
|
using TrueCraft.API;
|
||||||
using TrueCraft.Client.Rendering;
|
using TrueCraft.Client.Rendering;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
|
using Matrix = Microsoft.Xna.Framework.Matrix;
|
||||||
using XVector3 = Microsoft.Xna.Framework.Vector3;
|
using XVector3 = Microsoft.Xna.Framework.Vector3;
|
||||||
using TVector3 = TrueCraft.API.Vector3;
|
using TVector3 = TrueCraft.API.Vector3;
|
||||||
using TRay = TrueCraft.API.Ray;
|
using TRay = TrueCraft.API.Ray;
|
||||||
|
@ -3,6 +3,7 @@ using System.Diagnostics;
|
|||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Input;
|
using Microsoft.Xna.Framework.Input;
|
||||||
using TrueCraft.Client.Input;
|
using TrueCraft.Client.Input;
|
||||||
|
using Matrix = Microsoft.Xna.Framework.Matrix;
|
||||||
using TVector3 = TrueCraft.API.Vector3;
|
using TVector3 = TrueCraft.API.Vector3;
|
||||||
using XVector3 = Microsoft.Xna.Framework.Vector3;
|
using XVector3 = Microsoft.Xna.Framework.Vector3;
|
||||||
using TrueCraft.API;
|
using TrueCraft.API;
|
||||||
|
@ -24,7 +24,7 @@ namespace TrueCraft.Core.AI
|
|||||||
|
|
||||||
public WanderState()
|
public WanderState()
|
||||||
{
|
{
|
||||||
IdleChance = 20;
|
IdleChance = 10;
|
||||||
Distance = 25;
|
Distance = 25;
|
||||||
PathFinder = new AStarPathFinder();
|
PathFinder = new AStarPathFinder();
|
||||||
}
|
}
|
||||||
|
@ -116,11 +116,11 @@ namespace TrueCraft.Core.Entities
|
|||||||
// Advance along path
|
// Advance along path
|
||||||
var target = (Vector3)CurrentPath.Waypoints[CurrentPath.Index];
|
var target = (Vector3)CurrentPath.Waypoints[CurrentPath.Index];
|
||||||
target.Y = Position.Y; // TODO: Find better way of doing this
|
target.Y = Position.Y; // TODO: Find better way of doing this
|
||||||
var diff = target - Position;
|
|
||||||
diff *= modifier;
|
|
||||||
if (faceRoute)
|
if (faceRoute)
|
||||||
Face(target);
|
Face(target);
|
||||||
Position += diff;
|
var lookAt = Vector3.Forwards.Transform(Matrix.CreateRotationY(MathHelper.ToRadians(-(Yaw - 180) + 180)));
|
||||||
|
lookAt *= modifier;
|
||||||
|
Velocity = new Vector3(lookAt.X, Velocity.Y, lookAt.Z);
|
||||||
if (Position.DistanceTo(target) < 0.1)
|
if (Position.DistanceTo(target) < 0.1)
|
||||||
{
|
{
|
||||||
CurrentPath.Index++;
|
CurrentPath.Index++;
|
||||||
|
@ -33,6 +33,11 @@ namespace TrueCraft.Core
|
|||||||
return (int)(value * 32);
|
return (int)(value * 32);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static double ToRadians(double degrees)
|
||||||
|
{
|
||||||
|
return degrees * 0.017453292519943295769236907684886;
|
||||||
|
}
|
||||||
|
|
||||||
public static Coordinates3D BlockFaceToCoordinates(BlockFace face)
|
public static Coordinates3D BlockFaceToCoordinates(BlockFace face)
|
||||||
{
|
{
|
||||||
switch (face)
|
switch (face)
|
||||||
|
Reference in New Issue
Block a user