Unity 6.0.47f1 (if you tell me to update without a relevant reason I'm biting)
Unity Physics 1.3.14
NCE 1.3.6
Entities 1.3.14
Basically I'm struggling to work out how to do physics properly at all. I find watching video tutorials outdated or hard to concentrate on and anything readable either doesn't actually provide an example of usage (unity docs) or is outdated (ecs 0.5), and AI is doing typical AI things and making more problems than its fixing...
[UpdateInGroup(typeof(PredictedSimulationSystemGroup))]
[BurstCompile]
partial struct CubeMovementSystem : ISystem
{
[BurstCompile]
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<PhysicsWorldSingleton>();
state.RequireForUpdate<NetworkTime>();
}
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
var speed = SystemAPI.Time.DeltaTime * 4;
var physicsWorld = SystemAPI.GetSingleton<PhysicsWorldSingleton>().PhysicsWorld;
var networkTime = SystemAPI.GetSingleton<NetworkTime>();
foreach (var (input, owner, trans, predicted, entity) in SystemAPI.Query<RefRW<PlayerInput>, RefRO<GhostOwner>, RefRW<LocalTransform>, RefRO<PredictedGhost>>().WithAll<Simulate>().WithEntityAccess())
{
var moveInput = input.ValueRO.Move;
moveInput = moveInput * speed;
trans.ValueRW.Position += new float3(moveInput.x, 0, moveInput.y);
if (input.ValueRO.Jump)
{
if (SystemAPI.HasComponent<PhysicsVelocity>(entity) &&
SystemAPI.HasComponent<PhysicsMass>(entity))
{
int rigidBodyIndex = physicsWorld.GetRigidBodyIndex(entity);
float3 impulse = new float3(0, 5f, 0);
float3 point = trans.ValueRW.Position;
Debug.Log("Jump applied");
physicsWorld.ApplyImpulse(rigidBodyIndex, impulse, point);
input.ValueRW.Jump = false;
}
}
}
}
}
this is my current movement system, which is probably wrong in so many ways, and my input is a modified version of https://gist.github.com/JohnnyTurbo/f6dd1b6623fd9d17d2141091f8066825 that takes into account netcode behaviour.
Problem:
When I press space I get all the logs printed (although "Jump Applied" logs like 20 times even though it's a single client test) but the cube does not actually jump. It spawns in the air and falls down so physics is definitely otherwise working and automatically simulating.
What I want:
Direct transform based controls for WASD and physics based jumping so I can learn the basics of how this works and start making actual projects
Code used in ECS Input System tutorial video on the Turbo Makes Games YouTube Channel - https://youtu.be/bFHvgqLUDbE - FireProjectileSystem.cs