Commit b4e7688f by alsunj

Add slime target and moving system

parent 752a165c
Showing with 185 additions and 211 deletions
using Unity.Entities;
using UnityEngine;
public class DamageOnTriggerAuthoring : MonoBehaviour
public class DamageOnCollisionAuthoring : MonoBehaviour
{
public int DamageOnTrigger;
public class DamageOnTriggerBaker : Baker<DamageOnTriggerAuthoring>
public class DamageOnCollisionBaker : Baker<DamageOnCollisionAuthoring>
{
public override void Bake(DamageOnTriggerAuthoring authoring)
public override void Bake(DamageOnCollisionAuthoring authoring)
{
var entity = GetEntity(TransformUsageFlags.Dynamic);
AddComponent(entity, new DamageOnTrigger { Value = authoring.DamageOnTrigger });
AddComponent(entity, new DamageOnCollision { Value = authoring.DamageOnTrigger });
AddBuffer<AlreadyDamagedEntity>(entity);
}
}
......
......@@ -25,6 +25,7 @@ public class SlimeTargetAuthoring : MonoBehaviour
});
AddComponent<NpcTargetEntity>(entity);
AddComponent<SlimeTag>(entity);
AddComponent<SlimeTargetDirection>(entity);
AddBuffer<NpcAttackCooldown>(entity);
}
}
......
......@@ -23,10 +23,6 @@ public class EntitiesReferencesAuthoring : MonoBehaviour
SlimeEnemyEntity = GetEntity(authoring.SlimeEnemyGameObject, TransformUsageFlags.Dynamic),
RespawnEntity = GetEntity(authoring.RespawnEntity, TransformUsageFlags.None)
});
AddComponentObject(entity, new UIPrefabs
{
HealthBar = authoring.HealthBarPrefab,
});
}
}
}
......@@ -37,11 +33,5 @@ public struct EntititesReferences : IComponentData
public Entity PlayerPrefabEntity;
public Entity RougeEnemyEntity;
public Entity SlimeEnemyEntity;
public Entity RespawnEntity;
}
public class UIPrefabs : IComponentData
{
public GameObject HealthBar;
}
\ No newline at end of file
......@@ -46,7 +46,7 @@ public struct AbilityMoveSpeed : IComponentData
public float Value;
}
public struct DamageOnTrigger : IComponentData
public struct DamageOnCollision : IComponentData
{
public int Value;
}
......@@ -81,4 +81,9 @@ public struct CurrentHitPoints : IComponentData
public struct SlimeTag : IComponentData
{
}
public struct SlimeTargetDirection : IComponentData
{
public float3 Value;
}
\ No newline at end of file
using Unity.NetCode;
//[UnityEngine.Scripting.Preserve]
// public class GameBootstrap : ClientServerBootstrap
// {
// public override bool Initialize(string defaultWorldName)
// {
// AutoConnectPort = 7970;
// return base.Initialize(defaultWorldName);
// }
// }
\ No newline at end of file
......@@ -20,32 +20,10 @@ public struct PlayerSprintData : IComponentData
public float sprintCooldownReset;
}
public struct PlayerAttackData : IComponentData
{
public float attackCooldownTimer;
}
public struct PlayerDefenceData : IComponentData
{
public float defenceCooldownTimer;
}
public struct PlayerTag : IComponentData
{
}
[GhostComponent(PrefabType = GhostPrefabType.AllPredicted, OwnerSendType = SendToOwnerType.SendToOwner)]
public struct PlayerCameraBind : IComponentData
{
public int ClientNetworkId;
}
public struct CameraFollow : IComponentData
{
public Entity PlayerEntity;
public float3 Offset;
}
public struct TeamTypes : IComponentData
{
[GhostField] public TeamType Value;
......
......@@ -4,10 +4,6 @@ public struct GoInGameRequestRpc : IRpcCommand
{
}
public struct ClientConnectionRpc : IRpcCommand
{
}
public struct PlayersRemainingToStart : IRpcCommand
{
public int Value;
......
......@@ -5,11 +5,11 @@ using UnityEngine;
public class NetcodePlayerInputAuthoring : MonoBehaviour
{
public float sprintRemaining = 5f;
public float sprintDuration = 5f;
public float sprintSpeed = 12f;
public float walkSpeed = 9f;
public float sprintCooldownReset = 2f;
public float sprintRemaining;
public float sprintDuration;
public float sprintSpeed;
public float walkSpeed;
public float sprintCooldownReset;
public class Baker : Baker<NetcodePlayerInputAuthoring>
{
......@@ -20,19 +20,13 @@ public class NetcodePlayerInputAuthoring : MonoBehaviour
AddComponent(entity, new PlayerSprintData
{
isSprinting = false,
isSprintCooldown = false,
sprintRemaining = authoring.sprintRemaining,
sprintDuration = authoring.sprintDuration,
sprintSpeed = authoring.sprintSpeed,
walkSpeed = authoring.walkSpeed,
sprintCooldown = 0f,
sprintCooldownReset = authoring.sprintCooldownReset,
});
AddComponent(entity, new PlayerAttackData());
AddComponent(entity, new PlayerDefenceData());
AddComponent<PlayerTag>(entity);
}
}
}
}
\ No newline at end of file
......@@ -11,6 +11,7 @@ public partial struct ApplyDamageSystem : ISystem
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<NetworkTime>();
state.RequireForUpdate<GamePlayingTag>();
}
[BurstCompile]
......
......@@ -8,6 +8,8 @@ public partial struct CalculateFrameDamageSystem : ISystem
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<NetworkTime>();
state.RequireForUpdate<GamePlayingTag>();
state.RequireForUpdate<DamageBufferElement>();
}
[BurstCompile]
......
......@@ -12,6 +12,7 @@ public partial struct DamageOnCollisionSystem : ISystem
{
state.RequireForUpdate<SimulationSingleton>();
state.RequireForUpdate<EndSimulationEntityCommandBufferSystem.Singleton>();
state.RequireForUpdate<GamePlayingTag>();
}
[BurstCompile]
......@@ -20,7 +21,7 @@ public partial struct DamageOnCollisionSystem : ISystem
var ecbSingleton = SystemAPI.GetSingleton<EndSimulationEntityCommandBufferSystem.Singleton>();
var damageOnCollisionJob = new DamageOnCollisionJob
{
DamageOnTriggerLookup = SystemAPI.GetComponentLookup<DamageOnTrigger>(true),
DamageOnCollisionLookup = SystemAPI.GetComponentLookup<DamageOnCollision>(true),
TeamLookup = SystemAPI.GetComponentLookup<TeamTypes>(true),
AlreadyDamagedLookup = SystemAPI.GetBufferLookup<AlreadyDamagedEntity>(true),
DamageBufferLookup = SystemAPI.GetBufferLookup<DamageBufferElement>(true),
......@@ -34,7 +35,7 @@ public partial struct DamageOnCollisionSystem : ISystem
public struct DamageOnCollisionJob : ICollisionEventsJob
{
[ReadOnly] public ComponentLookup<DamageOnTrigger> DamageOnTriggerLookup;
[ReadOnly] public ComponentLookup<DamageOnCollision> DamageOnCollisionLookup;
[ReadOnly] public ComponentLookup<TeamTypes> TeamLookup;
public BufferLookup<AlreadyDamagedEntity> AlreadyDamagedLookup;
public BufferLookup<DamageBufferElement> DamageBufferLookup;
......@@ -49,12 +50,12 @@ public struct DamageOnCollisionJob : ICollisionEventsJob
Entity damageReceivingEntity = Entity.Null;
if (DamageBufferLookup.HasBuffer(entityA) &&
DamageOnTriggerLookup.HasComponent(entityB))
DamageOnCollisionLookup.HasComponent(entityB))
{
damageReceivingEntity = entityA;
damageDealingEntity = entityB;
}
else if (DamageOnTriggerLookup.HasComponent(entityA) &&
else if (DamageOnCollisionLookup.HasComponent(entityA) &&
DamageBufferLookup.HasBuffer(entityB))
{
damageDealingEntity = entityA;
......@@ -84,7 +85,7 @@ public struct DamageOnCollisionJob : ICollisionEventsJob
if (damageDealingTeam.Value == damageReceivingTeam.Value) return;
}
if (DamageOnTriggerLookup.TryGetComponent(damageDealingEntity, out var damageOnTrigger))
if (DamageOnCollisionLookup.TryGetComponent(damageDealingEntity, out var damageOnTrigger))
{
ECB.AddComponent<DestroyEntityTag>(damageDealingEntity);
ECB.AppendToBuffer(damageReceivingEntity, new DamageBufferElement { Value = damageOnTrigger.Value });
......
......@@ -6,6 +6,11 @@ using Unity.Transforms;
[UpdateInGroup(typeof(PredictedSimulationSystemGroup))]
public partial struct MoveAbilitySystem : ISystem
{
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<AbilityMoveSpeed>();
}
public void OnUpdate(ref SystemState state)
{
var deltaTime = SystemAPI.Time.DeltaTime;
......
using Unity.Burst;
using Unity.Entities;
using Unity.Mathematics;
using Unity.NetCode;
using Unity.Transforms;
......@@ -8,29 +8,34 @@ public partial struct MoveSlimeSystem : ISystem
{
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<AbilityMoveSpeed>();
state.RequireForUpdate<TeamTypes>();
state.RequireForUpdate<NpcTargetEntity>();
state.RequireForUpdate<NetworkTime>();
state.RequireForUpdate<EndSimulationEntityCommandBufferSystem.Singleton>();
state.RequireForUpdate<SlimeTargetDirection>();
state.RequireForUpdate<SlimeTag>();
}
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
var deltaTime = SystemAPI.Time.DeltaTime;
var localTransformLookup = SystemAPI.GetComponentLookup<LocalTransform>(true);
foreach (var (transform, moveSpeed, teamType, targetEntity) in SystemAPI
.Query<RefRW<LocalTransform>, RefRO<AbilityMoveSpeed>, RefRO<TeamTypes>, RefRO<NpcTargetEntity>>()
.WithAny<SlimeTag>())
state.Dependency = new MoveSlimeJob
{
if (teamType.ValueRO.Value == TeamType.Enemy && targetEntity.ValueRO.Value != Entity.Null)
{
if (localTransformLookup.HasComponent(targetEntity.ValueRO.Value))
{
var targetPosition = localTransformLookup[targetEntity.ValueRO.Value].Position;
var direction = math.normalize(targetPosition - transform.ValueRW.Position);
transform.ValueRW.Position += direction * moveSpeed.ValueRO.Value * deltaTime;
}
}
}
DeltaTime = deltaTime
}.ScheduleParallel(state.Dependency);
}
}
[BurstCompile]
[WithAll(typeof(SlimeTargetDirection))]
public partial struct MoveSlimeJob : IJobEntity
{
public float DeltaTime;
[BurstCompile]
private void Execute(ref LocalTransform transform, in AbilityMoveSpeed moveSpeed,
in SlimeTargetDirection targetDirection)
{
transform.Position += targetDirection.Value * moveSpeed.Value * DeltaTime;
}
}
\ No newline at end of file
......@@ -16,6 +16,7 @@ public partial struct NpcTargetingSystem : ISystem
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<PhysicsWorldSingleton>();
state.RequireForUpdate<GamePlayingTag>();
_npcAttackFilter = new CollisionFilter
{
BelongsTo = 1 << 6, //Target Cast
......
......@@ -6,12 +6,13 @@ using Unity.NetCode;
using Unity.Transforms;
[UpdateInGroup(typeof(PredictedSimulationSystemGroup))]
public partial struct NpcAttackSystem : ISystem
public partial struct RogueAttackSystem : ISystem
{
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<NetworkTime>();
state.RequireForUpdate<BeginSimulationEntityCommandBufferSystem.Singleton>();
state.RequireForUpdate<GamePlayingTag>();
}
public void OnUpdate(ref SystemState state)
......
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.Mathematics;
using Unity.NetCode;
using Unity.Transforms;
[UpdateInGroup(typeof(PredictedSimulationSystemGroup), OrderLast = true)]
[UpdateBefore(typeof(MoveSlimeSystem))]
public partial struct SetTargetSlimeSystem : ISystem
{
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<BeginSimulationEntityCommandBufferSystem.Singleton>();
state.RequireForUpdate<SlimeTag>();
state.RequireForUpdate<GamePlayingTag>();
}
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
var ecbSingleton = SystemAPI.GetSingleton<BeginSimulationEntityCommandBufferSystem.Singleton>();
var teamLookup = SystemAPI.GetComponentLookup<TeamTypes>(true);
var transformLookup = SystemAPI.GetComponentLookup<LocalTransform>(true);
state.Dependency = new SetSlimeTargetDirectionJob
{
TeamLookup = teamLookup,
TransformLookup = transformLookup,
Ecb = ecbSingleton.CreateCommandBuffer(state.WorldUnmanaged).AsParallelWriter()
}.ScheduleParallel(state.Dependency);
}
}
[BurstCompile]
public partial struct SetSlimeTargetDirectionJob : IJobEntity
{
[ReadOnly] public ComponentLookup<TeamTypes> TeamLookup;
[ReadOnly] public ComponentLookup<LocalTransform> TransformLookup;
public EntityCommandBuffer.ParallelWriter Ecb;
[BurstCompile]
private void Execute(in LocalTransform transform, in TeamTypes slimeTeam, in NpcTargetEntity targetEntity,
in Entity entity)
{
if (targetEntity.Value == Entity.Null || !TransformLookup.HasComponent(targetEntity.Value) ||
!TeamLookup.HasComponent(targetEntity.Value))
{
Ecb.RemoveComponent<SlimeTargetDirection>(entity.Index, entity);
return;
}
var targetTeam = TeamLookup[targetEntity.Value].Value;
if (targetTeam != TeamType.Enemy)
{
var targetPosition = TransformLookup[targetEntity.Value].Position;
var direction = math.normalize(targetPosition - transform.Position);
Ecb.AddComponent(entity.Index, entity, new SlimeTargetDirection { Value = direction });
}
else
{
Ecb.RemoveComponent<SlimeTargetDirection>(entity.Index, entity);
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 6236f73d74af5b04da99a398ca41c536
\ No newline at end of file
guid: 86f8c4a7fca9c2244981a82be26b0c7d
\ No newline at end of file
......@@ -32,7 +32,7 @@ public partial struct ClientRequestGameEntrySystem : ISystem
GameObject playerCameraGO = new GameObject($"Camera{networkId.ValueRO.Value}");
playerCameraGO.AddComponent<Camera>();
FollowPlayer followScript = playerCameraGO.AddComponent<FollowPlayer>();
followScript.networkId = networkId.ValueRO.Value; // Store networkId instead of dire
followScript.networkId = networkId.ValueRO.Value;
entityCommandBuffer.AddComponent<GoInGameRequestRpc>(requestGameConnection);
entityCommandBuffer.AddComponent<SendRpcCommandRequest>(requestGameConnection);
......
// using Unity.Burst;
// using Unity.Collections;
// using Unity.Entities;
// using Unity.NetCode;
// using UnityEngine;
//
// [WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation | WorldSystemFilterFlags.ThinClientSimulation)]
// partial struct GoInGameClientSystem : ISystem
// {
// [BurstCompile]
// public void OnCreate(ref SystemState state)
// {
// EntityQueryBuilder entityQueryBuilder = new EntityQueryBuilder(Allocator.Temp)
// .WithAll<NetworkId>()
// .WithNone<NetworkStreamInGame>();
// state.RequireForUpdate(state.GetEntityQuery(entityQueryBuilder));
// entityQueryBuilder.Dispose();
// }
//
// public void OnUpdate(ref SystemState state)
// {
// EntityCommandBuffer entityCommandBuffer = new EntityCommandBuffer(Unity.Collections.Allocator.Temp);
// foreach ((
// RefRO<NetworkId> networkId,
// Entity entity)
// in SystemAPI.Query
// <RefRO<NetworkId>>().WithNone<NetworkStreamInGame>().WithEntityAccess())
// {
// entityCommandBuffer.AddComponent<NetworkStreamInGame>(entity);
//
// Entity rpcEntity = entityCommandBuffer.CreateEntity();
// GameObject playerCameraGO = new GameObject($"Camera{networkId.ValueRO.Value}");
// playerCameraGO.AddComponent<Camera>();
//
// // Assign the player entity to FollowPlayer script
// FollowPlayer followScript = playerCameraGO.AddComponent<FollowPlayer>();
// followScript.networkId = networkId.ValueRO.Value; // Store networkId instead of dire
//
// entityCommandBuffer.AddComponent<GoInGameRequestRpc>(rpcEntity);
// entityCommandBuffer.AddComponent<SendRpcCommandRequest>(rpcEntity);
// }
//
// entityCommandBuffer.Playback(state.EntityManager);
// }
//
// [BurstCompile]
// public void OnDestroy(ref SystemState state)
// {
// }
// }
fileFormatVersion: 2
guid: fba7b32c8a6f16243985cbaa18fe1c44
\ No newline at end of file
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.NetCode;
[WorldSystemFilter(WorldSystemFilterFlags.ServerSimulation)]
partial struct ServerStartGameSystem : ISystem
{
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<NetworkTime>();
state.RequireForUpdate<GameStartProperties>();
state.RequireForUpdate<EntititesReferences>();
state.RequireForUpdate<GamePlayingTag>();
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 4b9f0553ae9c13c4a8e2e6161fdca969
\ No newline at end of file
......@@ -14,6 +14,8 @@ public partial struct DestroyEntitySystem : ISystem
state.RequireForUpdate<RespawnEntityTag>();
state.RequireForUpdate<BeginSimulationEntityCommandBufferSystem.Singleton>();
state.RequireForUpdate<NetworkTime>();
state.RequireForUpdate<GamePlayingTag>();
state.RequireForUpdate<DestroyEntityTag>();
}
public void OnUpdate(ref SystemState state)
......@@ -67,10 +69,6 @@ public partial struct DestroyEntitySystem : ISystem
ecb.DestroyEntity(entity); // Destroy non-player entities
}
}
else
{
transform.ValueRW.Position = new float3(1000f, 1000f, 1000f);
}
}
}
}
\ No newline at end of file
......@@ -9,6 +9,8 @@ public partial struct DestroyOnTimerSystem : ISystem
{
state.RequireForUpdate<NetworkTime>();
state.RequireForUpdate<EndSimulationEntityCommandBufferSystem.Singleton>();
state.RequireForUpdate<DestroyAtTick>();
state.RequireForUpdate<GamePlayingTag>();
}
[BurstCompile]
......@@ -19,10 +21,10 @@ public partial struct DestroyOnTimerSystem : ISystem
var currentTick = SystemAPI.GetSingleton<NetworkTime>().ServerTick;
foreach (var (destroyAtTick, entity) in SystemAPI.Query<DestroyAtTick>().WithAll<Simulate>()
foreach (var (destroyAtTick, entity) in SystemAPI.Query<RefRW<DestroyAtTick>>().WithAll<Simulate>()
.WithNone<DestroyEntityTag>().WithEntityAccess())
{
if (currentTick.Equals(destroyAtTick.Value) || currentTick.IsNewerThan(destroyAtTick.Value))
if (currentTick.Equals(destroyAtTick.ValueRW.Value) || currentTick.IsNewerThan(destroyAtTick.ValueRW.Value))
{
ecb.AddComponent<DestroyEntityTag>(entity);
}
......
......@@ -7,6 +7,8 @@ public partial struct InitializeDestroyOnTimerSystem : ISystem
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<NetworkTime>();
state.RequireForUpdate<DestroyOnTimer>();
state.RequireForUpdate<GamePlayingTag>();
}
public void OnUpdate(ref SystemState state)
......@@ -15,10 +17,10 @@ public partial struct InitializeDestroyOnTimerSystem : ISystem
var simulationTickRate = NetCodeConfig.Global.ClientServerTickRate.SimulationTickRate;
var currentTick = SystemAPI.GetSingleton<NetworkTime>().ServerTick;
foreach (var (destroyOnTimer, entity) in SystemAPI.Query<DestroyOnTimer>().WithNone<DestroyAtTick>()
foreach (var (destroyOnTimer, entity) in SystemAPI.Query<RefRW<DestroyOnTimer>>().WithNone<DestroyAtTick>()
.WithEntityAccess())
{
var lifetimeInTicks = (uint)(destroyOnTimer.Value * simulationTickRate);
var lifetimeInTicks = (uint)(destroyOnTimer.ValueRW.Value * simulationTickRate);
var targetTick = currentTick;
targetTick.Add(lifetimeInTicks);
ecb.AddComponent(entity, new DestroyAtTick { Value = targetTick });
......
......@@ -17,6 +17,7 @@ public partial class RespawnPlayerSystem : SystemBase
{
RequireForUpdate<NetworkTime>();
RequireForUpdate<TeamTypes>();
RequireForUpdate<GamePlayingTag>();
}
protected override void OnStartRunning()
......
......@@ -36,7 +36,7 @@ partial struct EnemySpawnerSystem : ISystem
float randomValue = aspect.RandomSpawnOffset;
float3 spawnPosition =
spawnPoints[slimeSpawnIndex].SpawnPoint + new float3(randomValue, 0, -randomValue);
SpawnEnemy(ecb, enemySlimeEntity, spawnPosition);
SpawnEnemy(ecb, enemySlimeEntity, spawnPosition);
aspect.IncreaseSlimeCounter();
aspect.ResetSlimeTimer();
}
......
using System;
using Unity.Burst;
using Unity.Entities;
using Unity.Mathematics;
......@@ -15,15 +16,19 @@ public partial class NetcodePlayerInputSystem : SystemBase
_inputActions = new InputSystem_Actions();
_inputActions.Enable();
RequireForUpdate<NetworkStreamInGame>();
RequireForUpdate<GamePlayingTag>();
RequireForUpdate<NetcodePlayerInput>();
RequireForUpdate<PlayerSprintData>();
}
protected override void OnUpdate()
{
foreach (RefRW<NetcodePlayerInput> netcodePlayerInput in SystemAPI.Query<RefRW<NetcodePlayerInput>>()
foreach ((RefRW<NetcodePlayerInput> netcodePlayerInput, RefRW<PlayerSprintData> playerSprintData)
in SystemAPI.Query<RefRW<NetcodePlayerInput>, RefRW<PlayerSprintData>>()
.WithAll<GhostOwnerIsLocal>())
{
netcodePlayerInput.ValueRW.inputVector = _inputActions.Player.Move.ReadValue<Vector2>();
playerSprintData.ValueRW.isSprinting = true;
}
}
......
......@@ -4,11 +4,22 @@ using Unity.Mathematics;
using Unity.NetCode;
using Unity.Physics;
using Unity.Transforms;
using UnityEngine;
[UpdateInGroup(typeof(PredictedSimulationSystemGroup))]
partial struct NetcodePlayerMovementSystem : ISystem
{
[BurstCompile]
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<NetcodePlayerInput>();
state.RequireForUpdate<PhysicsVelocity>();
state.RequireForUpdate<LocalTransform>();
state.RequireForUpdate<PlayerSprintData>();
state.RequireForUpdate<GamePlayingTag>();
}
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
float deltaTime = SystemAPI.Time.DeltaTime;
......@@ -22,41 +33,37 @@ partial struct NetcodePlayerMovementSystem : ISystem
{
float3 moveVector = new float3(netcodePlayerInput.ValueRO.inputVector.x, 0,
netcodePlayerInput.ValueRO.inputVector.y);
float moveSpeed = sprintData.ValueRO.isSprinting
? sprintData.ValueRO.sprintSpeed
: sprintData.ValueRO.walkSpeed;
float moveSpeed;
if (sprintData.ValueRO.isSprinting)
moveSpeed = sprintData.ValueRO.walkSpeed;
else
moveSpeed = sprintData.ValueRO.sprintSpeed;
// Update sprinting logic
if (sprintData.ValueRO.isSprinting && !sprintData.ValueRO.isSprintCooldown)
if (sprintData.ValueRO.isSprinting)
{
sprintData.ValueRW.sprintRemaining -= deltaTime;
if (sprintData.ValueRW.sprintRemaining <= 0)
if (!sprintData.ValueRO.isSprintCooldown)
{
sprintData.ValueRW.isSprinting = false;
sprintData.ValueRW.isSprintCooldown = true;
sprintData.ValueRW.sprintRemaining -= deltaTime;
if (sprintData.ValueRW.sprintRemaining <= 0)
{
sprintData.ValueRW.isSprintCooldown = true;
sprintData.ValueRW.sprintCooldown = sprintData.ValueRO.sprintCooldownReset;
}
}
}
else
{
sprintData.ValueRW.sprintRemaining = math.clamp(sprintData.ValueRW.sprintRemaining + deltaTime, 0,
sprintData.ValueRO.sprintDuration);
}
if (sprintData.ValueRO.isSprintCooldown)
{
sprintData.ValueRW.sprintCooldown -= deltaTime;
if (sprintData.ValueRW.sprintCooldown <= 0)
if (!sprintData.ValueRO.isSprintCooldown)
{
sprintData.ValueRW.isSprintCooldown = false;
sprintData.ValueRW.sprintCooldown = sprintData.ValueRO.sprintCooldownReset;
sprintData.ValueRW.sprintRemaining = math.clamp(sprintData.ValueRW.sprintRemaining + deltaTime, 0,
sprintData.ValueRO.sprintDuration);
}
}
// Apply smooth movement
physicsVelocity.ValueRW.Linear =
math.lerp(physicsVelocity.ValueRO.Linear, moveVector * moveSpeed, deltaTime * 10);
// Optionally, update the rotation to face the movement direction
if (!math.all(moveVector == float3.zero))
{
quaternion targetRotation = quaternion.LookRotationSafe(moveVector, math.up());
......
......@@ -150,9 +150,5 @@ public class ClientConnectionManager : MonoBehaviour
}
World.DefaultGameObjectInjectionWorld = clientWorld;
var ConnectionRequestEntity = clientWorld.EntityManager.CreateEntity();
clientWorld.EntityManager.AddComponentData(ConnectionRequestEntity, new ClientConnectionRpc());
}
}
\ No newline at end of file
......@@ -147,11 +147,11 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: a82f6d8766908894faabdee547539756, type: 3}
m_Name:
m_EditorClassIdentifier:
sprintRemaining: 5
sprintDuration: 5
sprintSpeed: 12
walkSpeed: 9
sprintCooldownReset: 2
sprintRemaining: 8
sprintDuration: 8
sprintSpeed: 25
walkSpeed: 1
sprintCooldownReset: 1
--- !u!114 &3955402020692204287
MonoBehaviour:
m_ObjectHideFlags: 0
......@@ -320,7 +320,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 8e73c985659b81d408f4e99cb152349d, type: 3}
m_Name:
m_EditorClassIdentifier:
MaxHitPoints: 20000
MaxHitPoints: 500
--- !u!1001 &6975352639711469968
PrefabInstance:
m_ObjectHideFlags: 0
......
......@@ -490,7 +490,7 @@ MonoBehaviour:
SlimeAmountContainer: {fileID: 7438304585132253661}
_connectButton: {fileID: 661734915}
_gameStartCountDownTime: 2
_slimeSpawnCooldownTime: 0.3
_slimeSpawnCooldownTime: 0.1
_rogueSpawnCooldownTime: 1
--- !u!114 &1734898360 stripped
MonoBehaviour:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment