Progress character movement
This commit is contained in:
1 parent
08e27ca2f1
commit
01f38a19a1
10 files changed
+160
-29
No files matched your search
@@ -0,0 +1,52 @@
|
||||
using System.Collections.Generic;
|
||||
using Unity.Entities;
|
||||
using Unity.Mathematics;
|
||||
using Unity.NetCode;
|
||||
using Unity.CharacterController;
|
||||
|
||||
public partial class DefaultVariantSystem : DefaultVariantSystemBase
|
||||
{
|
||||
protected override void RegisterDefaultVariants(Dictionary<ComponentType, Rule> defaultVariants)
|
||||
{
|
||||
defaultVariants.Add(typeof(KinematicCharacterBody), Rule.ForAll(typeof(KinematicCharacterBody_DefaultVariant)));
|
||||
defaultVariants.Add(typeof(CharacterInterpolation), Rule.ForAll(typeof(CharacterInterpolation_GhostVariant)));
|
||||
defaultVariants.Add(typeof(TrackedTransform), Rule.ForAll(typeof(TrackedTransform_DefaultVariant)));
|
||||
}
|
||||
}
|
||||
|
||||
[GhostComponentVariation(typeof(KinematicCharacterBody))]
|
||||
[GhostComponent()]
|
||||
public struct KinematicCharacterBody_DefaultVariant
|
||||
{
|
||||
// These two fields represent the basic synchronized state data that all networked characters will need.
|
||||
[GhostField()]
|
||||
public float3 RelativeVelocity;
|
||||
[GhostField()]
|
||||
public bool IsGrounded;
|
||||
|
||||
// The following fields are only needed for characters that need to support parent entities (stand on moving platforms).
|
||||
// You can safely omit these from ghost sync if your game does not make use of character parent entities (any entities that have a TrackedTransform component).
|
||||
[GhostField()]
|
||||
public Entity ParentEntity;
|
||||
[GhostField()]
|
||||
public float3 ParentLocalAnchorPoint;
|
||||
[GhostField()]
|
||||
public float3 ParentVelocity;
|
||||
}
|
||||
|
||||
// Character interpolation must only exist on predicted clients:
|
||||
// - for remote interpolated ghost characters, interpolation is handled by netcode.
|
||||
// - for server, interpolation is superfluous.
|
||||
[GhostComponentVariation(typeof(CharacterInterpolation))]
|
||||
[GhostComponent(PrefabType = GhostPrefabType.PredictedClient)]
|
||||
public struct CharacterInterpolation_GhostVariant
|
||||
{
|
||||
}
|
||||
|
||||
[GhostComponentVariation(typeof(TrackedTransform))]
|
||||
[GhostComponent()]
|
||||
public struct TrackedTransform_DefaultVariant
|
||||
{
|
||||
[GhostField()]
|
||||
public RigidTransform CurrentFixedRateTransform;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ad968c3972f1b5d45a01ff13d76c6073
|
||||
@@ -0,0 +1,46 @@
|
||||
using Unity.Mathematics;
|
||||
|
||||
public static class InputDeltaUtilities
|
||||
{
|
||||
public const float InputWrapAroundValue = 2000f;
|
||||
|
||||
public static void AddInputDelta(ref float input, float addedDelta)
|
||||
{
|
||||
input = math.fmod(input + addedDelta, InputWrapAroundValue);
|
||||
}
|
||||
|
||||
public static void AddInputDelta(ref float2 input, float2 addedDelta)
|
||||
{
|
||||
input = math.fmod(input + addedDelta, InputWrapAroundValue);
|
||||
}
|
||||
|
||||
public static float GetInputDelta(float currentValue, float previousValue)
|
||||
{
|
||||
float delta = currentValue - previousValue;
|
||||
|
||||
// When delta is very large, consider that the input has wrapped around
|
||||
if(math.abs(delta) > (InputWrapAroundValue * 0.5f))
|
||||
{
|
||||
delta += (math.sign(previousValue - currentValue) * InputWrapAroundValue);
|
||||
}
|
||||
|
||||
return delta;
|
||||
}
|
||||
|
||||
public static float2 GetInputDelta(float2 currentValue, float2 previousValue)
|
||||
{
|
||||
float2 delta = currentValue - previousValue;
|
||||
|
||||
// When delta is very large, consider that the input has wrapped around
|
||||
if(math.abs(delta.x) > (InputWrapAroundValue * 0.5f))
|
||||
{
|
||||
delta.x += (math.sign(previousValue.x - currentValue.x) * InputWrapAroundValue);
|
||||
}
|
||||
if(math.abs(delta.y) > (InputWrapAroundValue * 0.5f))
|
||||
{
|
||||
delta.y += (math.sign(previousValue.y - currentValue.y) * InputWrapAroundValue);
|
||||
}
|
||||
|
||||
return delta;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: edf2b03f9a1d4b22b732a2d347673c5a
|
||||
timeCreated: 1738609617
|
||||
Reference in new issue
Block a user