Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by BanzaiTree · Sep 25, 2011 at 11:47 PM · physicsfpstranslaterocket

How do I make a character controller "ride" a rocket?

Hi there,

I'm a bit of a Unity3D novice and could really use some pointers on a game that I'm building. It is a simple FPS game with one weapon: a really big rocket launcher. The character controller has within it a gun object that instantiates a rocket on left mouse click, and the rocket prefab has Constant Force on it so it flies forward. What I want to do is make it to on right mouse click, a rocket is instantiated and the player object is attached to it, with the FPS controls inactive. The point being that if the player clicks alternate-fire, they are able to ride on a rocket. Steering the rocket is done by moving the mouse. The player can jump off at any time and fall to the terrain, while the rocket continues on its trajectory.

So far, I've made it so when the game starts, a prefab (named Player) with the FPS controller in it is instantiated. Player has a Gun object (in the Mouselook) which has the script that instantiates rockets on mouse clicks, per the old Unity FPS tutorial. Movement controls and shooting rockets works fine. Just for kicks, I've also made a separate object with a capsule, camera, and mouselook on a Rocket object, with the mouse steering working. However, I don't think the "walking" player and the "flying" player modes should be separate objects. Rather, it seems to me like the logical way would be to have the Player prefab instance always remain, no matter if it was walking around with the FPS controls or sitting on a Rocket.

So, my main question is: How do I make the Player object physically attach itself to an instantiated Rocket object? I'm assuming I would update the Player's position with the Rocket's, but how do I refer back to the Player object from the script in the Rocket object?

Also: How do I disable the FPS controller (so they can't move with the arrow keys or jump) when a Player is riding on a Rocket?

Finally: How would I make the Player object's mouselook change the direction of the instantiated Rocket when the player is flying?

My apologies for loading this request with a lot of questions, and my general newbishness. I would genuinely appreciate any insight you guys could give me into these seemingly simple problems.

Thank you!

P.S. I originally posted this in the Unity Forums before I realized this might be a better place for it. Sorry for the cross-post!

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
0

Answer by SYNYST3R1 · Sep 26, 2011 at 01:26 AM

Have you tried making the player object a child of the rocket object? Not sure if that will work since I haven't done anything like that, but the position of the player will be that of the rocket if you make it a child object. You could disable the renderer then enable it when you want the rocket. That would be a really simple way if it works.

To disable a script you do something like this GetComponent("FPSController").enabled = false; then set it to true when you want it enabled.

You could make a call to the mouselook script using GetComponent and when you move the mouse x or y the rotation or position of the rocket changes. I believe there is two mouselook scripts one for x and one for y. Or you could do something like this without using the mouselook script in the update function/method of course

float speed = 1.0; transform.Rotate(Vector3(Input.GetAxis("Mouse Y"), Input.GetAxis("Mouse X"), 0) Time.deltaTime speed);

Comment
Add comment · 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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Rockets bending around enemies? 1 Answer

Fixing timestep to lower value showing wrong FPS 0 Answers

Why can't I shoot my bullet down? 1 Answer

Gravity only rigidbody 1 Answer

Limit & Scaling Translation Rate. 0 Answers


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