Setting position of object not updating on other clients
I am working on a script to allow for shooting. I am spawning bullets like this:
The bullets on the shooters screen spawn at the correct position, but on the other client they spawn at what looks to be 0, 0, 0. How would I do this correctly?
Solution:Jump to solution
----------------------
The issue you're experiencing is likely due to the fact that you're setting the position of the bullet after instantiating it. When you instantiate a Realtime prefab, it is instantiated on all clients. However, the position update you're making after instantiation is not being synchronized across all clients.
To solve this, you should use the
Realtime.Instantiate()
method that allows you to specify the position and rotation during instantiation. This will ensure that the position and rotation are set correctly on all clients.
...3 Replies
Hi @Kevin. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Solution
----------------------
The issue you're experiencing is likely due to the fact that you're setting the position of the bullet after instantiating it. When you instantiate a Realtime prefab, it is instantiated on all clients. However, the position update you're making after instantiation is not being synchronized across all clients.
To solve this, you should use the
Realtime.Instantiate()
method that allows you to specify the position and rotation during instantiation. This will ensure that the position and rotation are set correctly on all clients.
Here's how you can modify your code:
This version of the Realtime.Instantiate()
method is documented here (https://normcore.io/documentation/reference/classes/Normal.Realtime.Realtime).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1151175034346414100> kapa.ai is still learning and improving, please let us know how it did by reacting below