How to make a rigidbody stay on another rigidbody while moving?
Hello! I want to make a game like clustertrucks but I don't know how to make the rigidbody (the player) stay on the trucks (the other rigidbody) while they are moving forward and the player doesn't move anymore.
Answer by Larry-Dietz · Dec 07, 2019 at 06:15 PM
Quickest easiest way I can think of is to set your player as a child of the truck.
-Larry
I want to make the player stay on the truck. I don’t want any child in my game. If you want to help me then help me with some script or some ideas.
I tried to help you with a valid idea. $$anonymous$$aking the player a child of the truck, when the player "enters" the truck will make it move with the truck, then when you want to get out of the truck, set the player parent back to null.
As for code, I can give you pseudo code, since you provided no code to start with...
To "Enter" the truck...
Player.transform.parent = Truck.transform;
to "Exit" the truck...
Player.transform.parent = null;
Sorry. I am new with this and my $$anonymous$$d in slow. Anyway i don't want my character to stay in the truck. I want to stay on the top of the truck the truck. Can you help me with this?
To make it as simple as possible, do what Larry says =)
If your player is a child of the truck, you can always place it on the top of the truck.
Or you will enter the hell of the script and you will calculate a speed for your player based on the speed of the truck and the speed of the original player. This is not recommended and it will be less optimized than Larry's answer
Your answer
Follow this Question
Related Questions
Missing Reference Exception 1 Answer
Check if a boolean is true by use of a string 2 Answers
Photon not working/detected 2 Answers
How to use collision detection properly? 0 Answers