Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by arrowsmith · Apr 06, 2013 at 12:46 PM · vehiclemotorbike

Simple Motorbike control HELP!

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

Bike Image

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by AutoFredrik · Apr 06, 2013 at 06:50 PM

Just 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!

Comment
Add comment · Show 18 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image arrowsmith · Apr 06, 2013 at 07:40 PM 0
Share

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.

avatar image AutoFredrik · Apr 07, 2013 at 10:22 AM 0
Share

Ok, so I wrote a new answer for you about the scripting part, but when I hit "Submit" it said I couldn't post 2 answers on the same question, and everything I wrote was lost. Aaaargh! :) Anyway, I wrote this script for you, add it to your charater.

 `var rayDistance : int = 5; //how far will the raycast go?
  var cam : Tranform; //assign this to your camera.
  var yOffset : float = 0.5; //how high above the bike should the character be when he sits on it?

  function Update()
  {
  var hit : RaycastHit; //stores info about what the ray hits
  if(Physics.Raycast(cam.position, cam.forward, hit, rayDistance) && Input.Get$$anonymous$$ouseButtonDown(0))    
  /*looks for objects in front of us and checks if we click*/
  {
  if(hit.transform.root.name == "Bike") //if we did click we will check if the ray hit the bike. 
  {
  var bike : Transform = hit.transform.root; //stores the bike in a variable

  for(var bikePart in bike)
  bikePart.collider.enabled = false;

  transform.position = Vector3(bike.position.x, bike.position.y + yOffset, bike.position.z); /*moves character. a little bit  above the bike. The higher the yOffset the higher above the bike he sits.*/
  bike.rotation.y = transform.rotation.y; //rotates the bike so we're not riding sideways.
  bike.parent = transform; //parents the character to the bike so it will follow us
  }
  }
  }`

Just make sure that the bike or the bike's children have colliders. I hope this works! EDIT code now turns of the colliders of the bike's children when mounted.

avatar image AlucardJay · Apr 07, 2013 at 01:10 PM 0
Share

Just 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
avatar image arrowsmith · Apr 07, 2013 at 03:25 PM 0
Share

Oh 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?

avatar image AutoFredrik · Apr 07, 2013 at 06:03 PM 0
Share

Yepp, 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.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

My motorcycle's rear wheel doesn't slide like it does in real life when applying brakes 0 Answers

Riding a motorbike 0 Answers

how can i make a player get in a vehicle? 1 Answer

fast forward physic vehicles 0 Answers

Car rolls over when turning in real-time 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges