Can't get my player to move (parented to an obj w a rigid body)
Hello, I can't get my players movement to sync with my boat (my player moves a paddle which moves a boat's rigidy body) I'm feeling stuck and was wondering if someone could help me out?
33 Replies
Hi @nonnapasta. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Based on the information provided in the knowledge sources, there are a few important points to consider regarding your issue with syncing player movement to a boat object with a Rigidbody:
1. Parenting objects with RealtimeTransform components can cause issues. As mentioned in the RealtimeTransform documentation:
"Don't reparent game objects with RealtimeTransform on them! RealtimeTransform does not track the parent of a RealtimeTransform and cannot synchronize it at runtime."
2. For objects with Rigidbodies, it's recommended not to use parent-child relationships. From the RealtimeTransform documentation:
"To summarize, rigidbodies cannot have parent game objects unless the parent never moves."
3. Instead of parenting, a suggested approach is to use an empty game object and synchronize positions. The documentation recommends:
"Instead of reparenting, create an empty game object on your player character at the pick-up point. Then use a script that synchronizes the world position of the pick-up point object and the RealtimeTransform object that you would like to pick up."
To solve your specific issue, you might want to try the following:
1. Unparent your player from the boat object.
2. Create an empty game object as a reference point on the boat where the player should be.
3. Write a custom script to synchronize the player's position with this reference point on the boat.
4. Ensure that the boat's Rigidbody is properly synchronized using RealtimeTransform.
5. For the paddle movement, you may need to implement a custom RealtimeComponent to synchronize its state and apply forces to the boat's Rigidbody.
Remember, when working with Rigidbodies in Normcore, it's important to consider ownership. As stated in the Networked Physics guide:
"If you want to move an object, you need to request ownership of it."
If you're still having trouble after trying these suggestions, you may need to provide more details about your specific implementation for further assistance.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
<@346140392225374208> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@Normcore Assistant can you write scripts?
Let me check the knowledge base for you again. One moment! :books:
----------------------
I apologize, but I am specifically designed to answer questions about NormalVR and its related technologies. I don't write custom scripts or code. However, I can provide information and explanations about NormalVR's features, components, and best practices based on the official documentation. If you have any specific questions about using NormalVR or its scripting capabilities, I'd be happy to assist you with that.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
<@346140392225374208> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@Normcore Assistant I have created an empty on my boat, and want my players position to be synced to this position
Let me check the knowledge base for you again. One moment! :books:
----------------------
Based on your previous question and the current context, it seems you're trying to implement the suggestion of using an empty game object on your boat to synchronize your player's position. This is a good approach when dealing with Rigidbody objects in Normcore. Let's go through how you can achieve this using Normcore's components.
To synchronize your player's position to the empty game object on your boat, you can use RealtimeTransform components. Here's a general approach:
1. Ensure your boat has a RealtimeTransform component.
2. Add a RealtimeTransform component to your player object.
3. Create a script to synchronize the player's position with the empty game object on the boat.
Here's a basic example of how you might implement this synchronization:
Add this script to your player object and assign the empty game object on the boat to the
boatEmptyTransform
field in the inspector.
Remember these important points from the Normcore documentation:
1. Ownership is crucial. As mentioned in the Networked Physics guide:
"If you want to move an object, you need to request ownership of it."
2. Be cautious with Rigidbodies. From the RealtimeTransform documentation:
"When operating in Rigidbody mode, RealtimeTransform synchronizes the world position and rotation values in addition to all Rigidbody settings."
3. If you need to move the player relative to the boat, you might need to adjust the script to account for the boat's movement and rotation.
This approach should help you synchronize your player's position to the empty game object on your boat. If you encounter any specific issues or need further clarification, please let me know.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@346140392225374208> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Have you wired up a root game object into RealtimeAvatarManager?
put an empty game object in your scene that’s parented to the boat, wire that up to the Root slot on RealtimeAvatarManager
trying this now.
thank you for your help, read your wiki when I found normcore in the fall. fangirling rn
sweet! lmk if it works. happy to help
Hey @Max @Normcore Assistant , I'm still quite stuck. (Please keep in mind im new to Normcore & Networking in Unity) I'm confused how to use my local Player Root, Hands Etc, if it differs from my Local Avatar Prefab? Im just confused on the difference between the two and how setting up my local Player root will affect my player in the scene. Thanks for your assisstance and wonderful, free product
(Sorry for Spam) @Normcore Assistant Normcore Assistant , I'm still quite stuck. (Please keep in mind im new to Normcore & Networking in Unity) I'm confused how to use my local Player Root, Hands Etc, if it differs from my Local Avatar Prefab? Im just confused on the difference between the two and how setting up my local Player root will affect my player in the scene. Thanks for your assisstance and wonderful, free product
Let me check the knowledge base for you again. One moment! :books:
----------------------
No need to apologize! I'm here to help you understand Normcore better. Let's break down your question and clarify the concepts of local Player Root, Hands, and Local Avatar Prefab in the context of Normcore.
First, it's important to understand that Normcore uses a system of avatars to represent players in a multiplayer scene. The Local Avatar Prefab is the representation of your player that other users will see in the networked environment.
According to the XR Avatars and Voice Chat guide, Normcore provides a built-in system for creating XR avatars quickly. Here's how it works:
1. The RealtimeAvatarManager component is responsible for instantiating and managing avatars in the scene.
2. The Local Avatar Prefab is set in the RealtimeAvatarManager component. This prefab is instantiated to represent your local player in the networked environment.
3. The Local Avatar Prefab should include a RealtimeAvatar component on its root GameObject. This component is crucial for synchronizing the avatar's position, rotation, and other properties across the network.
Now, regarding your local Player Root and Hands:
1. Your local Player Root typically refers to the root GameObject of your player in the scene. This is usually where you'd attach your player controller scripts, camera, etc.
2. The Hands are usually child objects of your Player Root, representing the player's hands in VR/AR applications.
The key difference is that your local Player Root and Hands are for local control and input, while the Local Avatar Prefab is for network representation.
To set this up correctly:
1. Set up your local Player Root with your player controller, camera, and hands as you normally would for a single-player game.
2. Create a separate Avatar Prefab that represents your player visually. This should include the RealtimeAvatar component and any visual elements you want other players to see (e.g., a head model, hand models).
3. In your player controller script, you'll need to update the position and rotation of the Avatar Prefab based on your local Player Root's movement.
Here's a simplified example of how you might structure this:
Remember, this is a simplified example. You'll need to adapt it to your specific setup and requirements.
For more detailed information, I recommend checking out the XR Avatars and Voice Chat guide in the Normcore documentation. It provides step-by-step instructions on setting up avatars and customizing them for your needs.
If you're still having trouble, don't hesitate to ask for more clarification on specific parts of the setup process.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
<@346140392225374208> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
This answer is wrong lol. Happy to help
im all ears
so RealtimeAvatarManager spawns an avatar prefab for your local client. This avatar prefab instance will show up for everyone in the room.
Any transforms that you wire into the Local Player slot on RealtimeAvatarManager will be used to drive the avatar prefab instance that was instantiated for your client.
So if you wire up an empty game object to the Root, and move it to 5.0, 0.0, 0.0 then RealtimeAvatarManager will copy that position from your game object and set it on the root of the avatar prefab that it has instantiated for you
You'll typically want to put your Main Camera as a child game object of the Root so when the Root moves, the camera goes with it
got it
In your scene, you could have something like this:
sometimes people just use the Main Camera as the Head game object fwiw, nothing wrong with doing it that way too
okay,
Then if you wire those into the slots on RealtimeAvatarManager, they'll make sure your avatar prefab matches. Last up, if you parent this whole thing to your boat, when the boat moves, the head and hands game objects will go along with it
so essentially all of this is a child of my boat
what I'm scratching my head over is do I still include a copy of my boat for my avatar prefab?
I also have my paddle, which is connected to each unique boat. Currently when a boat's paddle is rowing, it moves the boat. How do I tie each root to each users boat?
that's a good point. if every player needs their own boat, you want the boat in the avatar prefab, but then you get this chicken and egg problem of of if the boat moves the Root, but it's also a child of the Root and then gets moved by it, it won't really work.
Typically what I'd recommend in this scenario is to separate the rigidbody for the boat and the visuals.
Actually, as I'm writing this out, I realize that might not be a good solution either, let me think for a sec.
Do you want people's boats to be able to collide with each other?
If you don't need the boats to collide, I would do it this way:
1. Put the rigidbody for the boat onto your Root game object in the scene.
2. Put the boat visuals / geometry in your avatar prefab.
3. Your paddles and things are also in the avatar prefab (so other players can see them), and they do an
if (realtimeView.isOwnedLocally) MoveRigidbody()
type call to move the rigidbody in the scene. That way only the avatar prefab for the local player moves the local rigidbody.
The downside to this is that there will only ever be one boat rigidbody instance in the scene and so collisions between players will not work.
If you do need the boats to collide, then it's a tad more complicated, but not too too bad?
1. Put your boat visuals / geometry + rigidbody into a prefab that has a RealtimeTransform on it.
2. Create your own MonoBehaviour component that sits on the same game object as RealtimeAvatarManager. Inside of Start()
, subscribe to Realtime.didConnectToRoom
(the source code for RealtimeAvatarManager includes an example of how to do this). When didConnectToRoom
fires you call Realtime.Instantiate("Boat Prefab");
. Essentially you instantiate a networked boat prefab for each player when they connect to the room.
3. You have your custom component reparent the Root game object to your networked boat prefab so your avatar moves along with it.okay sick, I'm gonna use this second version where boats will collide/ have their own rigid bodies
sounds good. that's probably what I would do too. A tiny bit more painful right now, but will be easier to work with later on.
how would you suggest accomplishing step #3? creating a script which moves the Root to an empty to a specific position of the boat?
does this check out for the code?
looks good to me. If the boat rigidbody is on the root of that boat prefab you can grab a reference to it in this script (Realtime.Instantiate will return a reference to the newly instantiated boat prefab) and pass it to your avatar so it can apply forces to the boat. Then in this script grab the position of the boat in Update and set it on the Root game object so the avatar moves with the boat
Hey Max, thanks for all your help. I'm going to implement this tomorrow. Thank you for your help, patience, and simple explanations. I can't wait to get Normcore fully implemented in my multiplayer VR game!
sounds good! keep me posted
Hey Max! I have players root's moving with their boat's rigid bodies! Players now move with their boat whenever they paddle. However I can't get the mesh of the boat to move with the player. I tried attaching its own realtime transform + view and that didnt work. I can get rigidbodies to sync in realtime but I can't get the meshes to sync in real time. (when I attach a realtime to the mesh it isn't able to move at all) Do i need some type of RequestOwnership script for the mesh of my boat? Attached is a screenshot of boats out of sync:
Thank you for all your help, this progress is very exciting!
Isn't the mesh a child of the boat rigidbody on the boat prefab?
If it's a child of the rigidbody it should move automatically with the rigidbody
you shouldn't have to separate the boat mesh and rigidbody if you're doing the option we talked about yesterday where everyone's boats can collide