增加收获属性逻辑,优化掉落物表现效果
This commit is contained in:
+9
-1
@@ -3,8 +3,16 @@ namespace SepCore.Simulation
|
||||
internal struct PickupStateSim : ISimulationComponent
|
||||
{
|
||||
public const int StateIdle = 0;
|
||||
public const int StateAbsorbing = 1;
|
||||
public const int StateAbsorbRequested = 1;
|
||||
public const int StateRecoil = 2;
|
||||
public const int StateDash = 3;
|
||||
public const int StateCollected = 4;
|
||||
|
||||
public int State;
|
||||
public float PhaseElapsed;
|
||||
public float IdleElapsed;
|
||||
public float FloatBaseHeight;
|
||||
public Unity.Mathematics.float3 RecoilStartPosition;
|
||||
public Unity.Mathematics.float3 RecoilDirection;
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -5,5 +5,6 @@ namespace SepCore.Simulation
|
||||
internal struct PickupTransformSim : ISimulationComponent
|
||||
{
|
||||
public float3 Position;
|
||||
public float3 Forward;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,9 @@ namespace SepCore.Simulation
|
||||
void SyncEnemyMovementInput(int entityId, bool isMoving, in Vector3 direction, float speed,
|
||||
bool avoidEnemyOverlap, float enemyBodyRadius, int separationIterations);
|
||||
|
||||
void SyncPlayerAbsorbSettings(float absorbRange, float absorbSpeed, float collectDistance);
|
||||
void SyncPlayerAbsorbSettings(float absorbRange, float absorbSpeed, float collectDistance,
|
||||
float recoilDistance, float recoilDuration, float dashAccelerationDuration,
|
||||
float dashMaxSpeedMultiplier, float turnSpeed);
|
||||
|
||||
void TriggerFullMapMagnet();
|
||||
}
|
||||
|
||||
+62
-25
@@ -12,30 +12,72 @@ namespace SepCore.Simulation
|
||||
private float _playerAbsorbRange = -1f;
|
||||
private float _playerAbsorbSpeed = -1f;
|
||||
private float _playerCollectDistance = -1f;
|
||||
private float _playerRecoilDistance = -1f;
|
||||
private float _playerRecoilDuration = -1f;
|
||||
private float _playerDashAccelerationDuration = -1f;
|
||||
private float _playerDashMaxSpeedMultiplier = -1f;
|
||||
private float _playerTurnSpeed = -1f;
|
||||
|
||||
public void SyncPlayerAbsorbSettings(float absorbRange, float absorbSpeed, float collectDistance)
|
||||
public void SyncPlayerAbsorbSettings(float absorbRange, float absorbSpeed, float collectDistance,
|
||||
float recoilDistance, float recoilDuration, float dashAccelerationDuration,
|
||||
float dashMaxSpeedMultiplier, float turnSpeed)
|
||||
{
|
||||
_playerAbsorbRange = absorbRange;
|
||||
_playerAbsorbSpeed = absorbSpeed;
|
||||
_playerCollectDistance = collectDistance;
|
||||
_playerRecoilDistance = recoilDistance;
|
||||
_playerRecoilDuration = recoilDuration;
|
||||
_playerDashAccelerationDuration = dashAccelerationDuration;
|
||||
_playerDashMaxSpeedMultiplier = dashMaxSpeedMultiplier;
|
||||
_playerTurnSpeed = turnSpeed;
|
||||
}
|
||||
|
||||
private float ResolveAbsorbRange()
|
||||
{
|
||||
if (_playerAbsorbRange >= 0f) return _playerAbsorbRange;
|
||||
return GameEntry.Luban != null ? GameEntry.Luban.Global.DefaultAbsorbRange : 2f;
|
||||
return GameEntry.Luban.Global.DefaultAbsorbRange;
|
||||
}
|
||||
|
||||
private float ResolveAbsorbSpeed()
|
||||
{
|
||||
if (_playerAbsorbSpeed >= 0f) return _playerAbsorbSpeed;
|
||||
return GameEntry.Luban != null ? GameEntry.Luban.Global.AbsorbSpeed : 8f;
|
||||
return GameEntry.Luban.Global.AbsorbSpeed;
|
||||
}
|
||||
|
||||
private float ResolveCollectDistance()
|
||||
{
|
||||
if (_playerCollectDistance >= 0f) return _playerCollectDistance;
|
||||
return GameEntry.Luban != null ? GameEntry.Luban.Global.CollectDistance : 0.5f;
|
||||
return GameEntry.Luban.Global.CollectDistance;
|
||||
}
|
||||
|
||||
private float ResolveRecoilDistance()
|
||||
{
|
||||
if (_playerRecoilDistance >= 0f) return _playerRecoilDistance;
|
||||
return GameEntry.Luban.Global.RecoilDistance;
|
||||
}
|
||||
|
||||
private float ResolveRecoilDuration()
|
||||
{
|
||||
if (_playerRecoilDuration >= 0f) return _playerRecoilDuration;
|
||||
return GameEntry.Luban.Global.RecoilDuration;
|
||||
}
|
||||
|
||||
private float ResolveDashAccelerationDuration()
|
||||
{
|
||||
if (_playerDashAccelerationDuration >= 0f) return _playerDashAccelerationDuration;
|
||||
return GameEntry.Luban.Global.DashAccelerationDuration;
|
||||
}
|
||||
|
||||
private float ResolveDashMaxSpeedMultiplier()
|
||||
{
|
||||
if (_playerDashMaxSpeedMultiplier >= 0f) return _playerDashMaxSpeedMultiplier;
|
||||
return GameEntry.Luban.Global.DashMaxSpeedMultiplier;
|
||||
}
|
||||
|
||||
private float ResolveTurnSpeed()
|
||||
{
|
||||
if (_playerTurnSpeed >= 0f) return _playerTurnSpeed;
|
||||
return GameEntry.Luban.Global.TurnSpeed;
|
||||
}
|
||||
|
||||
[Header("敌人互斥参数")]
|
||||
@@ -146,8 +188,14 @@ namespace SepCore.Simulation
|
||||
float absorbRange = ResolveAbsorbRange();
|
||||
float absorbSpeed = ResolveAbsorbSpeed();
|
||||
float collectDistance = ResolveCollectDistance();
|
||||
float recoilDistance = ResolveRecoilDistance();
|
||||
float recoilDuration = ResolveRecoilDuration();
|
||||
float dashAccelerationDuration = ResolveDashAccelerationDuration();
|
||||
float dashMaxSpeedMultiplier = ResolveDashMaxSpeedMultiplier();
|
||||
float turnSpeed = ResolveTurnSpeed();
|
||||
pickupMovementHandle = PickupMovementSystem.Schedule(_pickups, _collectedPickups, context.DeltaTime,
|
||||
planarPlayerPosition, absorbRange, absorbSpeed, collectDistance, default);
|
||||
planarPlayerPosition, absorbRange, absorbSpeed, collectDistance, recoilDistance,
|
||||
recoilDuration, dashAccelerationDuration, dashMaxSpeedMultiplier, turnSpeed, default);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,20 +280,12 @@ namespace SepCore.Simulation
|
||||
}
|
||||
else
|
||||
{
|
||||
var entityComponent = GameEntry.Entity;
|
||||
if (entityComponent != null)
|
||||
{
|
||||
entityComponent.HideEntity(drop);
|
||||
}
|
||||
GameEntry.Entity.HideEntity(drop);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var entityComponent = GameEntry.Entity;
|
||||
if (entityComponent != null)
|
||||
{
|
||||
entityComponent.HideEntity(entity);
|
||||
}
|
||||
GameEntry.Entity.HideEntity(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,19 +304,16 @@ namespace SepCore.Simulation
|
||||
}
|
||||
|
||||
var entityComponent = GameEntry.Entity;
|
||||
if (entityComponent != null && GameEntry.Luban != null)
|
||||
var group = entityComponent.GetEntityGroup(GameEntry.Luban.Global.PlayerGroupName);
|
||||
if (group != null && group.EntityCount > 0)
|
||||
{
|
||||
var group = entityComponent.GetEntityGroup(GameEntry.Luban.Global.PlayerGroupName);
|
||||
if (group != null && group.EntityCount > 0)
|
||||
var entities = group.GetAllEntities();
|
||||
for (int i = 0; i < entities.Length; i++)
|
||||
{
|
||||
var entities = group.GetAllEntities();
|
||||
for (int i = 0; i < entities.Length; i++)
|
||||
if (entities[i] is UnityGameFramework.Runtime.Entity ugfEntity &&
|
||||
ugfEntity.Logic is Player player && player.Available)
|
||||
{
|
||||
if (entities[i] is UnityGameFramework.Runtime.Entity ugfEntity &&
|
||||
ugfEntity.Logic is Player player && player.Available)
|
||||
{
|
||||
return player;
|
||||
}
|
||||
return player;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+21
-26
@@ -16,30 +16,22 @@ namespace SepCore.Simulation
|
||||
|
||||
public void OnLateUpdate()
|
||||
{
|
||||
if (_world == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var enemyManager = GameEntry.EnemyManager;
|
||||
if (enemyManager != null && enemyManager.Enemies != null)
|
||||
var enemies = enemyManager.Enemies;
|
||||
foreach (var enemy in enemies)
|
||||
{
|
||||
var enemies = enemyManager.Enemies;
|
||||
foreach (var enemy in enemies)
|
||||
if (enemy is not EnemyBase enemyEntity || !enemyEntity.Available)
|
||||
{
|
||||
if (enemy is not EnemyBase enemyEntity || !enemyEntity.Available)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!_world._enemies.TryGetSimulationIndex(enemyEntity.Id, out int simulationIndex))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
EnemyTransformSim enemyData = _world._enemies.Transform[simulationIndex];
|
||||
ApplyEnemyPresentation(enemyEntity, in enemyData);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!_world._enemies.TryGetSimulationIndex(enemyEntity.Id, out int simulationIndex))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
EnemyTransformSim enemyData = _world._enemies.Transform[simulationIndex];
|
||||
ApplyEnemyPresentation(enemyEntity, in enemyData);
|
||||
}
|
||||
|
||||
var projectiles = _world._projectiles;
|
||||
@@ -69,7 +61,15 @@ namespace SepCore.Simulation
|
||||
continue;
|
||||
}
|
||||
|
||||
pickupEntity.CachedTransform.position = ToVector3(pickups.Transform[i].Position);
|
||||
PickupTransformSim transformData = pickups.Transform[i];
|
||||
Transform pickupTransform = pickupEntity.CachedTransform;
|
||||
pickupTransform.position = ToVector3(transformData.Position);
|
||||
Vector3 forward = ToVector3(transformData.Forward);
|
||||
forward.y = 0f;
|
||||
if (forward.sqrMagnitude > float.Epsilon)
|
||||
{
|
||||
pickupTransform.rotation = Quaternion.LookRotation(forward.normalized, Vector3.up);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,11 +99,6 @@ namespace SepCore.Simulation
|
||||
in ProjectileTransformSim projectileData)
|
||||
{
|
||||
Transform projectileTransform = projectileEntity.CachedTransform;
|
||||
if (projectileTransform == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
projectileTransform.position = ToVector3(projectileData.Position);
|
||||
Vector3 forward = ToVector3(projectileData.Forward);
|
||||
if (forward.sqrMagnitude <= float.Epsilon)
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace SepCore.Simulation
|
||||
{
|
||||
public int EntityId;
|
||||
public Vector3 Position;
|
||||
public Vector3 Forward;
|
||||
public float PickupRadius;
|
||||
public int State;
|
||||
}
|
||||
|
||||
+1
@@ -95,6 +95,7 @@ namespace SepCore.Simulation
|
||||
{
|
||||
EntityId = pickupEntity.Id,
|
||||
Position = pickupEntity.CachedTransform.position,
|
||||
Forward = pickupEntity.CachedTransform.forward,
|
||||
PickupRadius = 0.35f
|
||||
};
|
||||
}
|
||||
|
||||
+22
-5
@@ -290,6 +290,7 @@ namespace SepCore.Simulation
|
||||
{
|
||||
EntityId = entityId,
|
||||
Position = ToVector3(transform.Position),
|
||||
Forward = ToVector3(transform.Forward),
|
||||
PickupRadius = radius.Radius,
|
||||
State = state.State
|
||||
};
|
||||
@@ -302,9 +303,9 @@ namespace SepCore.Simulation
|
||||
|
||||
return _pickups.Add(
|
||||
new PickupIdentitySim { EntityId = simData.EntityId },
|
||||
new PickupTransformSim { Position = ToFloat3(simData.Position) },
|
||||
new PickupTransformSim { Position = ToFloat3(simData.Position), Forward = ToFloat3(simData.Forward) },
|
||||
new PickupRadiusSim { Radius = simData.PickupRadius },
|
||||
new PickupStateSim { State = simData.State });
|
||||
new PickupStateSim { State = simData.State, FloatBaseHeight = simData.Position.y });
|
||||
}
|
||||
|
||||
internal int UpsertPickup(in PickupSimData simData)
|
||||
@@ -315,9 +316,17 @@ namespace SepCore.Simulation
|
||||
}
|
||||
|
||||
_pickups.Identity[index] = new PickupIdentitySim { EntityId = simData.EntityId };
|
||||
_pickups.Transform[index] = new PickupTransformSim { Position = ToFloat3(simData.Position) };
|
||||
_pickups.Transform[index] = new PickupTransformSim
|
||||
{
|
||||
Position = ToFloat3(simData.Position),
|
||||
Forward = ToFloat3(simData.Forward)
|
||||
};
|
||||
_pickups.Radius[index] = new PickupRadiusSim { Radius = simData.PickupRadius };
|
||||
_pickups.State[index] = new PickupStateSim { State = simData.State };
|
||||
_pickups.State[index] = new PickupStateSim
|
||||
{
|
||||
State = simData.State,
|
||||
FloatBaseHeight = simData.Position.y
|
||||
};
|
||||
return index;
|
||||
}
|
||||
|
||||
@@ -326,7 +335,15 @@ namespace SepCore.Simulation
|
||||
int pickupCount = _pickups.Count;
|
||||
for (int i = 0; i < pickupCount; i++)
|
||||
{
|
||||
_pickups.State[i] = new PickupStateSim { State = PickupStateSim.StateAbsorbing };
|
||||
PickupStateSim state = _pickups.State[i];
|
||||
if (state.State != PickupStateSim.StateIdle)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
state.State = PickupStateSim.StateAbsorbRequested;
|
||||
state.PhaseElapsed = 0f;
|
||||
_pickups.State[i] = state;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+178
-36
@@ -11,14 +11,10 @@ namespace SepCore.Simulation
|
||||
// W CollectedPickups
|
||||
public static JobHandle Schedule(PickupStore pickups, NativeList<int> collectedPickups,
|
||||
float deltaTime, float3 playerPosition, float absorbRange, float absorbSpeed, float collectDistance,
|
||||
JobHandle dependency)
|
||||
float recoilDistance, float recoilDuration, float dashAccelerationDuration,
|
||||
float dashMaxSpeedMultiplier, float turnSpeed, JobHandle dependency)
|
||||
{
|
||||
int pickupCount = pickups.Count;
|
||||
if (pickupCount == 0)
|
||||
{
|
||||
return dependency;
|
||||
}
|
||||
|
||||
PickupMovementJob job = new PickupMovementJob
|
||||
{
|
||||
Transforms = pickups.Transform.Data.AsArray(),
|
||||
@@ -27,9 +23,14 @@ namespace SepCore.Simulation
|
||||
Radii = pickups.Radius.Data.AsArray(),
|
||||
CollectedPickups = collectedPickups.AsParallelWriter(),
|
||||
PlayerPosition = playerPosition,
|
||||
AbsorbRange = math.max(0f, absorbRange),
|
||||
AbsorbSpeed = math.max(0f, absorbSpeed),
|
||||
CollectDistance = math.max(0f, collectDistance),
|
||||
AbsorbRange = absorbRange,
|
||||
AbsorbSpeed = absorbSpeed,
|
||||
CollectDistance = collectDistance,
|
||||
RecoilDistance = recoilDistance,
|
||||
RecoilDuration = recoilDuration,
|
||||
DashAccelerationDuration = dashAccelerationDuration,
|
||||
DashMaxSpeedMultiplier = dashMaxSpeedMultiplier,
|
||||
TurnSpeedRadians = math.radians(turnSpeed),
|
||||
DeltaTime = deltaTime
|
||||
};
|
||||
return job.Schedule(pickupCount, 64, dependency);
|
||||
@@ -39,6 +40,10 @@ namespace SepCore.Simulation
|
||||
[BurstCompile]
|
||||
internal struct PickupMovementJob : IJobParallelFor
|
||||
{
|
||||
private const float IdleFloatAmplitude = 0.08f;
|
||||
private const float IdleFloatAngularFrequency = 3.14159265f;
|
||||
private const float IdleRotationSpeedRadians = 0.610865238f;
|
||||
|
||||
public NativeArray<PickupTransformSim> Transforms;
|
||||
public NativeArray<PickupStateSim> States;
|
||||
[ReadOnly] public NativeArray<PickupIdentitySim> Identities;
|
||||
@@ -48,52 +53,189 @@ namespace SepCore.Simulation
|
||||
public float AbsorbRange;
|
||||
public float AbsorbSpeed;
|
||||
public float CollectDistance;
|
||||
public float RecoilDistance;
|
||||
public float RecoilDuration;
|
||||
public float DashAccelerationDuration;
|
||||
public float DashMaxSpeedMultiplier;
|
||||
public float TurnSpeedRadians;
|
||||
public float DeltaTime;
|
||||
|
||||
public void Execute(int index)
|
||||
{
|
||||
PickupTransformSim transform = Transforms[index];
|
||||
PickupStateSim state = States[index];
|
||||
PickupIdentitySim identity = Identities[index];
|
||||
PickupRadiusSim radius = Radii[index];
|
||||
|
||||
float3 currentPosition = transform.Position;
|
||||
float3 horizontalPosition = new float3(currentPosition.x, 0f, currentPosition.z);
|
||||
float3 toPlayer = PlayerPosition - horizontalPosition;
|
||||
float sqrDistance = math.lengthsq(toPlayer);
|
||||
|
||||
float effectiveCollectDistance = math.max(CollectDistance, radius.Radius);
|
||||
float sqrCollectDistance = effectiveCollectDistance * effectiveCollectDistance;
|
||||
|
||||
if (sqrDistance <= sqrCollectDistance)
|
||||
if (state.State == PickupStateSim.StateCollected)
|
||||
{
|
||||
CollectedPickups.AddNoResize(identity.EntityId);
|
||||
return;
|
||||
}
|
||||
|
||||
bool isAbsorbing = state.State == PickupStateSim.StateAbsorbing;
|
||||
bool shouldAbsorb = isAbsorbing || (AbsorbRange > 0f && sqrDistance <= AbsorbRange * AbsorbRange);
|
||||
PickupIdentitySim identity = Identities[index];
|
||||
PickupRadiusSim radius = Radii[index];
|
||||
float effectiveCollectDistance = math.max(CollectDistance, radius.Radius);
|
||||
float deltaTime = DeltaTime;
|
||||
|
||||
if (shouldAbsorb && AbsorbSpeed > 0f && sqrDistance > float.Epsilon)
|
||||
if (state.State == PickupStateSim.StateIdle)
|
||||
{
|
||||
state.State = PickupStateSim.StateAbsorbing;
|
||||
float distance = math.sqrt(sqrDistance);
|
||||
float step = AbsorbSpeed * DeltaTime;
|
||||
state.IdleElapsed = math.fmod(state.IdleElapsed + deltaTime,
|
||||
2f * math.PI / IdleFloatAngularFrequency);
|
||||
transform.Position.y = state.FloatBaseHeight +
|
||||
math.sin(state.IdleElapsed * IdleFloatAngularFrequency) * IdleFloatAmplitude;
|
||||
RotateWhileIdle(ref transform, deltaTime);
|
||||
|
||||
if (step >= distance)
|
||||
float3 toPlayer = PlayerPosition - transform.Position;
|
||||
toPlayer.y = 0f;
|
||||
if (AbsorbRange <= 0f || math.lengthsq(toPlayer) > AbsorbRange * AbsorbRange || AbsorbSpeed <= 0f)
|
||||
{
|
||||
transform.Position = new float3(PlayerPosition.x, currentPosition.y, PlayerPosition.z);
|
||||
CollectedPickups.AddNoResize(identity.EntityId);
|
||||
Transforms[index] = transform;
|
||||
States[index] = state;
|
||||
return;
|
||||
}
|
||||
|
||||
BeginRecoil(ref transform, ref state, PlayerPosition);
|
||||
}
|
||||
else if (state.State == PickupStateSim.StateAbsorbRequested)
|
||||
{
|
||||
BeginRecoil(ref transform, ref state, PlayerPosition);
|
||||
}
|
||||
|
||||
float remainingDeltaTime = deltaTime;
|
||||
if (state.State == PickupStateSim.StateRecoil && remainingDeltaTime > 0f)
|
||||
{
|
||||
if (RecoilDuration <= 0f)
|
||||
{
|
||||
transform.Position = state.RecoilStartPosition + state.RecoilDirection * RecoilDistance;
|
||||
state.State = PickupStateSim.StateDash;
|
||||
state.PhaseElapsed = 0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
float3 direction = toPlayer / distance;
|
||||
transform.Position = currentPosition + direction * step;
|
||||
}
|
||||
float phaseRemaining = RecoilDuration - state.PhaseElapsed;
|
||||
float stepTime = math.min(remainingDeltaTime, phaseRemaining);
|
||||
state.PhaseElapsed += stepTime;
|
||||
float recoilProgress = math.saturate(state.PhaseElapsed / RecoilDuration);
|
||||
transform.Position = state.RecoilStartPosition +
|
||||
state.RecoilDirection * (RecoilDistance * recoilProgress);
|
||||
remainingDeltaTime -= stepTime;
|
||||
|
||||
Transforms[index] = transform;
|
||||
States[index] = state;
|
||||
if (state.PhaseElapsed >= RecoilDuration)
|
||||
{
|
||||
state.State = PickupStateSim.StateDash;
|
||||
state.PhaseElapsed = 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (state.State == PickupStateSim.StateDash)
|
||||
{
|
||||
float3 toPlayer = PlayerPosition - transform.Position;
|
||||
toPlayer.y = 0f;
|
||||
float distance = math.length(toPlayer);
|
||||
if (distance <= effectiveCollectDistance)
|
||||
{
|
||||
MarkCollected(ref state, identity.EntityId);
|
||||
}
|
||||
else if (remainingDeltaTime > 0f && AbsorbSpeed > 0f)
|
||||
{
|
||||
float step = GetDashDistance(AbsorbSpeed, state.PhaseElapsed, remainingDeltaTime,
|
||||
DashAccelerationDuration, DashMaxSpeedMultiplier);
|
||||
float distanceToCollect = distance - effectiveCollectDistance;
|
||||
float movedDistance = math.min(step, distanceToCollect);
|
||||
transform.Position += toPlayer / distance * movedDistance;
|
||||
state.PhaseElapsed += remainingDeltaTime;
|
||||
if (movedDistance >= distanceToCollect)
|
||||
{
|
||||
MarkCollected(ref state, identity.EntityId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RotateTowardPlayer(ref transform, PlayerPosition, deltaTime);
|
||||
Transforms[index] = transform;
|
||||
States[index] = state;
|
||||
}
|
||||
|
||||
private static void BeginRecoil(ref PickupTransformSim transform, ref PickupStateSim state,
|
||||
float3 playerPosition)
|
||||
{
|
||||
float3 direction = transform.Position - playerPosition;
|
||||
direction.y = 0f;
|
||||
if (math.lengthsq(direction) <= float.Epsilon)
|
||||
{
|
||||
direction = new float3(0f, 0f, -1f);
|
||||
}
|
||||
else
|
||||
{
|
||||
direction = math.normalize(direction);
|
||||
}
|
||||
|
||||
state.State = PickupStateSim.StateRecoil;
|
||||
state.PhaseElapsed = 0f;
|
||||
state.RecoilStartPosition = transform.Position;
|
||||
state.RecoilDirection = direction;
|
||||
if (math.lengthsq(transform.Forward) <= float.Epsilon)
|
||||
{
|
||||
transform.Forward = new float3(0f, 0f, 1f);
|
||||
}
|
||||
}
|
||||
|
||||
private static void RotateWhileIdle(ref PickupTransformSim transform, float deltaTime)
|
||||
{
|
||||
float3 forward = transform.Forward;
|
||||
forward.y = 0f;
|
||||
forward = math.lengthsq(forward) <= float.Epsilon
|
||||
? new float3(0f, 0f, 1f)
|
||||
: math.normalize(forward);
|
||||
|
||||
transform.Forward = math.normalize(math.rotate(
|
||||
quaternion.AxisAngle(new float3(0f, 1f, 0f), IdleRotationSpeedRadians * deltaTime), forward));
|
||||
}
|
||||
|
||||
private void MarkCollected(ref PickupStateSim state, int entityId)
|
||||
{
|
||||
state.State = PickupStateSim.StateCollected;
|
||||
CollectedPickups.AddNoResize(entityId);
|
||||
}
|
||||
|
||||
private static float GetDashDistance(float speed, float elapsed, float deltaTime,
|
||||
float accelerationDuration, float maxSpeedMultiplier)
|
||||
{
|
||||
if (accelerationDuration <= 0f)
|
||||
{
|
||||
return speed * maxSpeedMultiplier * deltaTime;
|
||||
}
|
||||
|
||||
float acceleratedUntil = math.min(accelerationDuration, elapsed + deltaTime);
|
||||
float acceleratedDuration = math.max(0f, acceleratedUntil - elapsed);
|
||||
float averageMultiplier = 1f + (maxSpeedMultiplier - 1f) *
|
||||
(elapsed + acceleratedUntil) / (2f * accelerationDuration);
|
||||
float distance = speed * acceleratedDuration * averageMultiplier;
|
||||
float constantDuration = deltaTime - acceleratedDuration;
|
||||
return distance + speed * maxSpeedMultiplier * constantDuration;
|
||||
}
|
||||
|
||||
private void RotateTowardPlayer(ref PickupTransformSim transform, float3 playerPosition,
|
||||
float deltaTime)
|
||||
{
|
||||
float3 targetDirection = playerPosition - transform.Position;
|
||||
targetDirection.y = 0f;
|
||||
if (math.lengthsq(targetDirection) <= float.Epsilon)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
targetDirection = math.normalize(targetDirection);
|
||||
float3 currentForward = transform.Forward;
|
||||
currentForward.y = 0f;
|
||||
currentForward = math.lengthsq(currentForward) <= float.Epsilon
|
||||
? new float3(0f, 0f, 1f)
|
||||
: math.normalize(currentForward);
|
||||
|
||||
float signedAngle = math.atan2(math.cross(currentForward, targetDirection).y,
|
||||
math.dot(currentForward, targetDirection));
|
||||
float angleStep = math.clamp(signedAngle, -TurnSpeedRadians * deltaTime,
|
||||
TurnSpeedRadians * deltaTime);
|
||||
transform.Forward = math.normalize(math.rotate(quaternion.AxisAngle(new float3(0f, 1f, 0f), angleStep),
|
||||
currentForward));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user