- Home /
Moving with rotating object
I'm creating a simple platformer. The player is able to move only left and right. So this rotating wheel (think cylinder), is supposed to move the player towards the direction it's rotating to. So if the wheel is rotating right, the player would move right along with wheel.
I've tried making it the child of the wheel but the issue with that is that the player also rotates with the object (player moves with the wheel but also rotates around). Also I can't walk the opposite way of the rotation.
If I understand correctly: You have a player character that can jump on a rotating wheel. The player rotates along with the wheel, correct? I assume the player is supposed to stay upright while the cylinder/wheel rotates (otherwise parenting would do the trick)? Or are the feet of the character "glued" to the surface of the cylinder?
Yes, the player is supposed to stay upright but parenting the character causes the player to rotate.
O$$anonymous$$. The easiest way I can think of (on top of my head) is that you parent the player to the cylinder in any case. This should give the impression that the player is rotating along with the cylinder and his/her feet are see$$anonymous$$gly glued to the surface. If your character is doing cartwheels and revolving around its own axis (i.e. doing some sort of extra rotation) than you did something wrong with the parenting. You can easily test the required behaviour by creating two cubes, spacing them apart, parent one to the other and then change the rotation values of the transform component of the parent. Always start with a basic test, you don't need to throw in your prefabs from the get-go.
That said, if you want your character's head to keep "pointing towards the sky" during the rotation, that's a bit trickier. Start out the the same by parenting the player to the cylinder. However, this time, apply a rotation to the character equal to the rotation of the cylinder but in the opposite direction. For example: if your cylinder has a rotation of 45 degrees, your character should have a (local!) rotation of -45 to stay upright. Be sure to experiment in the editor before writing any code: use two cubes, parent them and play with their transform component to properly understand how parenting works.
Again, this is just of the top of my head. I'm at work right now. I can try to type out a decent answer (maybe throw some code and pics in the mix) to your question tonight, if you want. There are different ways to solve this though and it really depends on your situation. If you're coding a platformer and the cylinder is a wheel the player can jump on, then parenting might not be desired.
Good luck!
Sam
Answer by Drakulo · Jan 23, 2014 at 12:16 PM
I guess setting up the wheel as child of your player will do the trick.
I don't get what your cylinder is for. Is it a controller for the player ?
The cylinder is rotating ( like a car wheel), so when the player goes on top- the player moves with the direction the wheel is rotating. However when made child of the wheel, the player also rotates (doing cartwheels)
Your answer
Follow this Question
Related Questions
Getting the face direction 2 Answers
Character Controller falls through moving/rotating platforms (Not A Duplicate Post) 1 Answer
Why does my rotating platform not pause when I pause the game? 1 Answer
How to recycle obstacles in an Endless Runner? 1 Answer
Unity AI Obstacle Avoidance Help 3 Answers