Rigibody adding force
Two players both have code that can add force to a rigidbody, but only one owns the rigibody, do I need to add a check to make sure the player that does not own the rigibody will a not add force? Or does realtime transform cause any other updates to get ignored so it is not a problem to have this conflict for the player who does not own the rigibody?
5 Replies
Hi @cryptomax. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To answer your question about adding force to a Rigidbody in a multiplayer scenario using NormalVR's Normcore, we need to consider how RealtimeTransform handles ownership and physics synchronization.
According to the Networked Physics (https://normcore.io/documentation/realtime/networked-physics) documentation:
"To solve this problem,
RealtimeTransform
introduces the concept of ownership. When an object is owned by a client, their simulation is considered the source of truth for that object. RealtimeTransform
synchronizes the state of the object from the owner to all other clients."
This means that only the owner of the RealtimeTransform component can effectively modify the Rigidbody's state. However, it's still a good practice to add a check before applying force to ensure that only the owning client attempts to modify the Rigidbody. This is because:
1. It's more efficient to avoid unnecessary calculations on non-owning clients.
2. It makes your code's intent clearer and easier to maintain.
You can add a check like this before applying force:
While RealtimeTransform will ensure that only the owner's updates are synchronized across the network, adding this check can help prevent potential conflicts and improve performance by avoiding unnecessary calculations on non-owning clients.
It's worth noting that according to the RealtimeTransform documentation (https://normcore.io/documentation/realtime/realtimetransform#transform-mode-vs-rigidbody-mode):
"When operating in Rigidbody mode, RealtimeTransform synchronizes the world position and rotation values in addition to all Rigidbody settings."
This means that even if a non-owning client attempts to add force, the RealtimeTransform component will override these changes with the owner's state during synchronization.
In conclusion, while RealtimeTransform will ultimately ensure that only the owner's updates are reflected across the network, it's still recommended to add an ownership check before applying force to a Rigidbody for better code clarity and efficiency.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@401986039964631060> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@Normcore Assistant so it's not strictly necessary it's just the proper way to handle it 🙂
Let me check the knowledge base for you again. One moment! :books:
----------------------
You're correct! Your understanding is spot on.
As per the RealtimeTransform documentation (https://normcore.io/documentation/realtime/realtimetransform), it's not strictly necessary to add the ownership check, but it is indeed the proper and recommended way to handle it.
The RealtimeTransform component will ensure that only the owner's updates are synchronized across the network. However, adding the ownership check before applying force to a Rigidbody has several benefits:
1. It improves code efficiency by avoiding unnecessary calculations on non-owning clients.
2. It makes your code's intent clearer, which enhances maintainability.
3. It follows best practices for working with Normcore's ownership system.
So while your game would likely function correctly without the check due to RealtimeTransform's behavior, including it is considered good practice in Normcore development. It's a small addition that can lead to cleaner, more efficient, and more easily understood code.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
<@401986039964631060> Kapa.ai is still learning and improving, please let me know how I did by reacting below.