#Physics are being funny
1 messages · Page 1 of 1 (latest)
tank collider looks like this
and here body settings for it
box collider at the same time is primitive (it's also static)
here physics step settings
oh also, this is netcode. But tank is interpolated
This is how I apply velocity.
public void OnUpdate(ref SystemState state)
{
var speed = SystemAPI.Time.DeltaTime * 4;
foreach (var (tank, trans, physicsVelocity) in SystemAPI
.Query<TankInput, RefRO<LocalTransform>, RefRW<PhysicsVelocity>>()
.WithAll<Simulate>())
{
ref var pv = ref physicsVelocity.ValueRW;
ref readonly var tf = ref trans.ValueRO;
ref readonly var inp = ref tank;
var moveInput = new float2(inp.horizontal, inp.vertical) * speed;
var direction = math.sign(inp.vertical);
direction = math.select(direction, 1f, direction == 0f);
pv.Linear += tf.TransformDirection(new(0f, 0f, moveInput.y * 3f));
pv.Angular.y += moveInput.x * direction;
}
}
funny jumps happen specifically when I do horizontal input (apply angular velocity)
@mental elk ^
@crimson tulip : Hi! Do confirm my understanding, you are moving the tank with the code above?
And when it collides with some other rigid body (in this case this static green box) you get these excessive forces applied to the tank and it gets bounced off?
When are you updating your system exactly? You should make sure to update it either entirely before the PhysicsSystemGroup or after.
yep.
To specify: it collides with it's edges. And edges are smoothed by very high bevel radius
When you run this without netcode, do you get the same behavior?
Also, have you tried removing the bevel radius altogether?
whole project is actually public, if you need repro. One sec, I'll find relevant info
here link
https://github.com/bustedbunny/RTSDemo
[UpdateInGroup(typeof(BeforePhysicsSystemGroup))]
[WorldSystemFilter(WorldSystemFilterFlags.ServerSimulation)]
public partial struct TankMovementSystem : ISystem
there it is
You could just try to modify a few things and see if you can find a clue of what could be causing this.
As I said, I'd suggest to try it without netcode, and get rid of the bevel radius for starters and see if that works.
That would give us an indication what to look for.
without netcode? 🤔
I mean, just running this as a pure physics simulation without any netcode content.
No client/server. Just to see if the issue is physics, or netcode + physics related.
That would help us understand better what to look for.
Also, in the NetcodeSamples project this exact use case is modeled also and it is stable.
I think this one here should be quite close to what you are doing:
https://github.com/Unity-Technologies/EntityComponentSystemSamples/tree/master/NetcodeSamples/Assets/Scenes/Multiphysics
Some static objects which are present everywhere (client and server) and some client only particles that collide with a synchronized dynamic entity.
The dynamic entity is controlled with either forces or velocity modifications. I am not sure right now.