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
0
Question by Kulahan · Aug 15, 2011 at 06:42 PM · car

exiting a car at the same spot every time??

Ok, so I'm having a small issue with my car that apparently no one else has run into. If I get out of my car while it's facing in its original direction, I exit riiiight beside the driver's side door. Unfortunately, however, if I turn the car around, I exit right near the back right-hand side of the car. If I face my car to the right of it's original position, I exit by the back of the car. Get the idea? In the code that I'm about to include, I was wondering if someone could show me what I'd need to throw in there so that I always exit with my character standing by the driver's side door, regardless of the orientation of the car. Thanks in advance!

 else if (inVehicle) {
             rigidbody.isKinematic = true;
             inVehicle = false;
             nextToVehicle = false;
             VehicleCam.camera.enabled = false;
             Player = Instantiate(GameObject.Find("Clone"), transform.position + new Vector3(-2, 0, 0), transform.rotation) as GameObject;
             Player.name = "Player";
             Player.tag = "Player";
             CharacterMotor PlayerScript = Player.GetComponent<CharacterMotor>();
             PlayerScript.canControl = true;
             miniMapScript.playerTransform = Player.transform;
             followScript.target = Player.transform;
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Rennat · Aug 15, 2011 at 09:24 PM

 ...
 // doesn't work
 // offsetting by global coordinates the same direction every time
 Vector3 exitPosition = transform.position + new Vector3(-2, 0, 0);

 // does work
 // offset taking transform rotation into account
 Vector3 exitPosition = transform.position + transform.right * -2;

 Player = Instantiate(GameObject.Find("Clone"), exitPosition, transform.rotation) as GameObject;
 ...
Comment
Add comment · Show 5 · 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 Kulahan · Aug 16, 2011 at 02:44 PM 0
Share

So I'm a bit confused as to how this would work, mostly because of the fact that your solution is in javascript, and, unfortunately, my code is in C#. Any chance you could translate it? That would be a HUGE help. Thanks!

avatar image Rennat · Aug 16, 2011 at 02:59 PM 0
Share

You're right it is C#, I wasn't paying attention. Editing my answer.

avatar image Kulahan · Aug 16, 2011 at 03:09 PM 0
Share

You are my hero. I don't know why I couldn't figure this out, but you've seriously made my day.

avatar image Rennat · Aug 23, 2011 at 09:03 PM 0
Share

Hi @$$anonymous$$ulahan, would you "thumbs up" this answer? I'm kind of a $$anonymous$$arma whore. :)

avatar image Kulahan · Aug 24, 2011 at 01:07 PM 0
Share

I would love to, but for some reason it says I don't have permission :/ Sorry Edgar Allen Bro.

avatar image
1

Answer by illwunn · Aug 15, 2011 at 06:59 PM

Maybe add an empty game object that is a child of the vehicle and use it as a spawn point, position it by the drivers side door and use it's position as the reference position in your instantiate

Comment
Add comment · Show 3 · 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 Kulahan · Aug 15, 2011 at 07:23 PM 0
Share

That won't work - I have way too many cars in this game for me to sit around and add invisible boxes to all of 'em. Just a huge pain in the ass. I feel like something along the lines of a vector3(transform.eulerangles.x - 2, etc, etc) would work, but for some reason, it's not. Any ideas?

avatar image illwunn · Aug 15, 2011 at 07:26 PM 0
Share

ah i c, well i see you are using the world position in your instantiate, have you considered using the local position of your vehicle? try using transform.localposition

avatar image Kulahan · Aug 15, 2011 at 07:30 PM 0
Share

unfortunately, that doesn't work - it does the same thing as the normal world position. I spawn at the same spot, regardless of how I orient the vehicle.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Void loop? 2 Answers

Brake Light Button 1 Answer

Make a noise when i crash into something 1 Answer

need tutorials for rigidbody.Addforce 1 Answer

Make car CenterOfMass change dynamically 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