Hayden
Hayden2mo ago

RequestOwnership() and a ball

I am working on a simple game that involves players applying forces to a shared ball. Documentation suggests that I should use RequestOwnership() to do this, but I am having trouble getting it to function as described. What am I missing? Thank you.
Solution:
also you only need ownership of the realtime transform
Jump to solution
11 Replies
kapa.ai
kapa.ai2mo ago
Hi @Hayden. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- In NormalVR, the RequestOwnership() function is used to designate which client is responsible for the movement of a game object. If you're trying to apply forces to a shared ball, you'll need to ensure that the client applying the force is the owner of the ball's RealtimeTransform component. Here's a simple example of how you might use RequestOwnership():
GameObject myObject = Realtime.Instantiate("My Object");

// Get the RealtimeView component
RealtimeView myObjectView = myObject.GetComponent<RealtimeView>();

// Mark the RealtimeView owned by the local client
myObjectView.RequestOwnership();
GameObject myObject = Realtime.Instantiate("My Object");

// Get the RealtimeView component
RealtimeView myObjectView = myObject.GetComponent<RealtimeView>();

// Mark the RealtimeView owned by the local client
myObjectView.RequestOwnership();
After calling RequestOwnership(), only the local client can make changes to the RealtimeView and any child views or components on myObject. If you want to clear the ownership later, you can use myObjectView.ClearOwnership(). It's important to note that RequestOwnership() and ClearOwnership() take effect immediately, but if the server blocks the request—say, because preventOwnershipTakeover is true or because the view's parent is owned by another client—then ownership and all changes that required ownership will be rolled back. If you're still having trouble, it might be because Normcore doesn’t send changes to the server immediately when you change ownership or the value on a model. Instead, it synchronizes at 20hz and sends the latest state. If you change something and then change it back immediately, nothing will be sent to the server. In this case, you might want to skip calling ClearOwnership(). For more information, you can refer to the RealtimeTransform documentation (https://normcore.io/documentation/realtime/realtimetransform) and the Common Questions (https://normcore.io/documentation/realtime/common-questions) section of the Normcore documentation. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@143551436603654145> kapa.ai is still learning and improving, please let us know how it did by reacting below
Hayden
Hayden2mo ago
Thanks, that's pretty much what I'd gathered as well. I'll go through it again.
Mechabit
Mechabit2mo ago
the way realtime transform works is one player takes ownership of the ball and then sends updates to other players of the new position and velocity but depending on the type of game you're making that will look better or worse if you're the owner. also if 2 people request ownership at the same time and both move the ball the last update sent to the server will override the first player's move if you need both forces to be cumulative you'll probably need a custom solution
Hayden
Hayden2mo ago
Interesting. Well, that does make sense. What I'm seeing though is that, even as the only player, I'm not able to apply force to the ball via script unless I collide with it, after which I can do so It's as if the RequestOwnership() call isn't returning
Mechabit
Mechabit2mo ago
make sure clear ownership on sleep is off
Solution
Mechabit
Mechabit2mo ago
also you only need ownership of the realtime transform
Hayden
Hayden2mo ago
that was it! it works 🙂 thank you
Towellie
Towellie2mo ago
Hey! What one was it if you dont mind - make sure clear ownership on sleep is off or - also you only need ownership of the Realtime transform
Hayden
Hayden2mo ago
Hi! I already had the first one set, and the second one is when it started working.
Towellie
Towellie2mo ago
Awesome thank you!