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 Cobalt60 · Dec 06, 2011 at 03:18 AM · cameraviewfirst person controller

How to have controlles switch from FPC to a RC Car

Hello Unity Community! I have been having the greatest time in Unity3d but have come across a problem. I am trying to have were the player, which would be a First Person Controller comes to a control stand (3d model)is able to press a key, say the button D button on the key board. This function sends the controlles and camera to a RC car witch the player can operate. Once the person is done using the RC car he is able to exit out or when he dies he is returned to his original body. I would complete this objective by myself but can not script worth a darn. Any scripts or references to a website with the required programming would be fantastic. Thank You so much Sincerely, Cobalt 60

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
3
Best Answer

Answer by ByteSheep · Dec 07, 2011 at 02:54 AM

If you have a script to control your player and a script to control your RC car (I'm assuming you have already created individual controls for both), then you can use a variable to enable or disable the control scripts: GetComponent("ScriptName").enabled = false;

With this you can dis/en-able your scripts.. It could look something like this:

 var PlayerGameObject : GameObject;
 var CarGameObject : GameObject;
 
 var Player : Transform;
 var Car : Transform;
 var PlayerDied : boolean = false;
 
 function Update () {
 
     if(Input.GetButtonUp("D"))
     {
         if(Player.GetComponent("ScriptName").enabled == true && Car.GetComponent("test").enabled == false)
         {
         Player.GetComponent("test").enabled = false;
         Car.GetComponent("test").enabled = true;
         
         PlayerGameObject.camera.enabled = false;
         CarGameObject.camera.enabled = true;
         }
         
         if(Player.GetComponent("ScriptName").enabled == false && Car.GetComponent("test").enabled == true || PlayerDied == true)
         {
         Player.GetComponent("test").enabled = true;
         Car.GetComponent("test").enabled = false;
         
         PlayerGameObject.camera.enabled = true;
         CarGameObject.camera.enabled = false;
         }
 
 
     }
 
 
 }


You will have to assign all of the variables (GameObjects and Transforms) in the inspector view and you may have to define the Input key "D" under Edit>Project Settings>Input . You will also have to set PlayerDied to true when your player dies, hope this helps!

Comment
Add comment · Show 9 · 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 ByteSheep · Dec 08, 2011 at 06:04 PM 0
Share

And forgot to mention the "ScriptName" and "test" must be replaced with the names of your scripts

avatar image Cobalt60 · Dec 22, 2011 at 06:08 AM 0
Share

So sorry to ask this but is it possible to put a range where you can get in the car when you are 5 feet away or so. thanks for everything you have done so far.

avatar image ByteSheep · Dec 22, 2011 at 07:31 AM 0
Share

Yes that should be simple enough, add this script to the car object:

var player : Transform; var dist : float; static var InRange : boolean; var $$anonymous$$Distance : float = 5;

function Update () {

dist = Vector3.Distance(player.transform.position, transform.position);

if(dist

}

Then name this script "CarDistance" and find the line: if(Input.GetButtonUp("D")) in the first script.

Turn that line into:
if(Input.GetButtonUp("D") && CarDistance.InRange == true)

This script is calculating the distance between the players transform and the cars transform, getting a float value that (when lower than $$anonymous$$Distance) will set InRange to true. The other script is checking whether InRange is true and will therefor only allow the player to enter the vehicle if close enough ;)

avatar image Cobalt60 · Dec 22, 2011 at 11:50 PM 0
Share

Thank you so much you are the best :)

avatar image Cobalt60 · Dec 23, 2011 at 06:15 PM 0
Share

Thank you so much I don't think I will ever be able to repay you and I am sorry for adding and adding to the script. I was wondering if it was possible that when the person uses the rc car or vehicle it takes the player with the vehicle and when the player decides to get out it drops him off where the vehicle had stoped. Thank you so much for everything.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Camera not Following Inspector's Value (Transform) When Play 0 Answers

Toggle Control between multiple turrets 0 Answers

Viewer position lost in Space. How to get back to scene? 1 Answer

How do I calculate a view matrix using Matrix4x4.LookAt? 2 Answers

How to change first person controller input when passing through a collider? 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