I’m pretty new to Unity.
I’ve made a motorbike in 3DS Max, with all of the objects grouped into “frame”, “front wheel” and “back wheel” (see the links below). What I want to be able to do is have the first person controller be able to mount the bike and then move it as they would if they were still in the first person controller mode. I don’t need any wheel animation, no turning of the handle bars, just the ability to mount the bike and essentially walk around as the bike. Is there any simple way to do this? Thanks
1 Answer
1Just attatch the bike model as a child to the first person controller and it will follow the player wherever he goes! You do this by placing the bike in a position where it looks like the player is riding it and, in the hierachy drag the bike to the controller to make it a child of the controller. That’s a very simple solution, but it will do what you asked for. If you want the player to be able to walk around and click on the bike to get up on it, you will need to do some scripting. It would basically be a script where you check if the player clicks on the bike using raycast, and then move the bike to where the player is (or the other way around) and parent the bike to the controller. I can help you with that too, if you want to. Also, make sure that the bike has no collider attached or things will get messed up when the player moves.
Hope this helps. Nice model by the way!
Oh! That sounds so simple, you're so right! :P I'll give that a try, thanks so much for your quick response. I would appreciate some help with the scripting if it's quite short - don't want to take too much of your time. And thanks, took a good while.
– arrowsmithJust simply Edit your answer to include the code. Write : Hope this helps. Nice model by the way! Edit : Here is some script to demonstrate : // add your code // to your answer
– AlucardJayOh damn, I'm sorry it did that. That's awesome thanks so much for writing this! So, now I should have the player and bike separated in the hierarchy, save this code as a script in Unity and just drop it onto my character?
– arrowsmithYepp, pretty much. Just make sure to assign the "cam" variable to the camera attached to your first person controller. And remove the "`" in the end and beginning of the script, I wrote it from my phone and they showed up for some reason. The script can't make the player get off the bike, he can only get on :) And don't forget to add som form of collider to the bike.
– AutoFredrikSee, I told you I was new to Unity, got it now! :P Thanks for your patience. That's all fine now your code works great. I've added mesh colliders to every object in the bike, however when I mount it, the bike turns upside down and moving around becomes sluggish - not sure what this is due to? [1] [1]: http://postimg.org/image/lmpoc8dy7/
– arrowsmith