Fix camera changing position during microbe rotation#6966
Fix camera changing position during microbe rotation#6966
Conversation
…owing point of the camera
From my personal point of view, this solution might be confusing for players. I think it's quite important for the lead cell to stay in the center of screen. |
ImanProductions
left a comment
There was a problem hiding this comment.
my game freezes when I try to start a new playthrew
|
There was some additional context for this PR in Discord. And also there has been player requests for centering the camera on the center of a cell colony. So fundamentally I think this would be a good change. Though there are quite many considerations with other code. But still I think this is a good approach to take as if our physics engine applies rotation on the center of mass rather than local origin of a physics body, this logic fix will make things easier. However one quite key point is that right now cell orientation is set based on a look vector from entity origin to a world position, so if the camera centering point is changed then the look position point algorithm or cell rotation target algorithm has to be updated to match, otherwise rotation will get really hard to manage if the camera is a significant distance away from the entity origin. |
|
|
||
| (position.Position, position.Rotation) = physicalWorld.ReadBodyPosition(body); | ||
|
|
||
| physics.CenterOfMassPosition = physicalWorld.ReadBodyCenterOfMassPosition(body); |
There was a problem hiding this comment.
Rather than constantly reading and saving this in Physics component, I think this should either be cached in the physics shape wrapper or just directly re-read by the systems that really need this.
Because I think re-reading this for each body on each frame in the base position system is a major waste of processing power.
| { | ||
| const JPH::Body& body = lock.GetBody(); | ||
|
|
||
| positionReceiver = body.GetCenterOfMassPosition(); |
There was a problem hiding this comment.
An interesting note here: Jolt internally stores bodie's positions as the center of mass position. However, our normal read does internally in Jolt a reverse translation to get the origin: mPosition - mRotation * mShape->GetCenterOfMass();
So in effect to get the center of mass, we can take the position we read back already and apply the center of mass and rotation to it from the physics shape. Thus I believe that while this method is useful to exist, we should probably structure this PR for performance reasons to have a cached shape center of mass that exists on our C# shape wrapper for easy access. And then we should be able to just use the shape + WorldPosition to get the center of mass: position.Position + position.Rotation * shape.CenterOfMass (shape.CenterOfMass would be a new property here).
Brief Description of What This PR Does
Apparently, microbe cells were rotated around their center of mass instead of their position, while the camera followed their normal position. This caused the bug that this PR is marked as fixing.
Now that the camera follows the center of mass, there is a side effect; it follows colonies' center instead of the lead cell. Let me know if this is undesirable; there might be an alternate solution
Related Issues
Fix #4696
Progress Checklist
Note: before starting this checklist the PR should be marked as non-draft.
break existing features:
https://wiki.revolutionarygamesstudio.com/wiki/Testing_Checklist
(this is important as to not waste the time of Thrive team
members reviewing this PR). This includes gameplay testing by the PR author.
styleguide.
Before merging all CI jobs should finish on this PR without errors, if
there are automatically detected style issues they should be fixed by
the PR author. Merging must follow our
styleguide.