Neos-Metaverse / NeosPublic

A public issue/wiki only repository for the NeosVR project
193 stars 9 forks source link

Applying forces and impulses to a CharacterController via LogiX does not account for mass #2737

Closed Zyzyl closed 3 years ago

Zyzyl commented 3 years ago

Describe the bug?

I assume that the Neos' physics simulation is intended to approximate Newtonian mechanics and that technical terms such as 'forces' and 'impulses' have equivalent meanings. In Newtonian physics, applying both a force or an impulse to a body may produce a change in linear velocity, however the body's mass is relevant in calculating the resultant velocity in both cases. However, it seems that the Mass field of a CharacterController is ignored when applying either of these using the Apply Character Force or Apply Character Impulse LogiX nodes.

According to Newton's Second Law (https://en.wikipedia.org/wiki/Newton%27s_laws_of_motion#Newton's_second_law), a force acting on a body will produce an acceleration equal to Force / Mass. I assume that the Apply Character Force node is simulating applying a constant force equal to the Force input on the node for the duration of one update when it receives an impulse. In the absence of other forces acting on the relevant CharacterController, I'd therefore expect a linear velocity change equal to Force / Mass * dT. Instead it seems Neos changes the velocity by Force * dT.

In Newtonian mechanics, an Impulse is defined as the integral of a force applied to a mass over a time duration (https://en.wikipedia.org/wiki/Impulse_(physics)). Effectively, an impulse applied to a body would cause an equal change in the body's linear momentum, which is defined as the mass * velocity. I assume that the Apply Character Impulse node is simulating applying an instantaneous impulse equal to the Impulse input on the node when it receives a LogiX impulse. In the absence of other forces acting on the relevant CharacterController, I'd therefore expect a linear velocity change equal to Impulse / Mass. Instead it seems Neos changes the velocity by Impulse.

Relevant issues

None that I could find.

To Reproduce

This behaviour should be visible any time one of the relevant nodes is used. An example would be:

  1. Create a new world using the Physical Locomotion Test preset.
  2. Change to ZeroG locomotion (to eliminate gravity force).
  3. Apply either Force or Impulse using LogiX to the local user.
  4. Changing the Mass values in the active locomotion CharacterController makes no difference to the resulting linear velocity.

I have also set up a demo world where this can be observed using a sphere mesh with a CharacterController applied. All that is required is to input a SimulatingUser to the CharacterController. I have recorded a video from this world and linked it below.

Expected behavior

When an Apply Character Force node receives a LogiX impulse, I'd expect a linear velocity change in the relevant character controller equal to Force / Mass * dT. Instead it seems Neos changes the velocity by Force * dT.

When an Apply Character Force node receives a LogiX impulse, I'd expect a linear velocity change in the relevant character controller equal to Impulse / Mass. Instead it seems Neos changes the velocity by Impulse.

I believe at least the Apply Character Force node is intended to take mass into account as per https://discord.com/channels/402159838827905024/731903736028332083/735581549361234060, however it seems Froox and I may have a different expectations for Apply Character Impulse.

I note the CharacterController also has a MassScaling enum which I assume is intended to scale the effective mass depending on the (Global?) scale of the CharacterController's slot. I would therefore expect the (Global?) scale of an object to affect the mass value used in the above calculations.

Log Files

No response

Screenshots

https://youtu.be/zOh-6XswHfI

How often does it happen?

Always

Does the bug persist after restarting Neos?

Yes

Neos Version Number

2021.8.2.936

What Platforms does this occur on?

Windows

Link to Reproduction Item/World

neosrec:///U-Zyzyl/R-97f35359-4073-42bd-954e-de9df76efe88

Did this work before?

No

If it worked before, on which build?

No response

Additional context

No response

Reporters

Zyzyl#1441

Frooxius commented 3 years ago

Fixed in 2021.8.25.1127 as part of BEPUv2 upgrade, there's now a input for controlling whether mass is respected or not. Thanks for reporting this!