• 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 NinjaDesigns · Dec 12, 2013 at 06:25 PM · local axis

Appearing to a local GameObject Child but off axis

So hard to describe in the title but basically when I eject from an airplane and its spinning off axis. I think the problem is im spawning to a GameObject Child of the plane in Local space so when i appear as the plane is in a roll, my character spawns upside down or whatever LocalRotation it is currently in and then I land on my side or head and stuck.

exitPoint.parent = jet.transform; exitPoint.transform.localPosition = Vector3(-2.5,0,0);

So exitPosition is the GameObject my player reappears at when he gets out (-2.5) is just offset enough to clear the plane and no collision issues.

Im guessing it needs to be in World.Rotation or something along those lines. Newbie here pulling his hair out, self taught.

Thanks for reading and happy designing!

Comment
Add comment · Show 2
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 guitarxe · Dec 12, 2013 at 06:34 PM 0
Share

Nobody knows the game you're creating and thus nobody can tell what's going on from your description of jumping out of planes.

Please be more clear, precise, and show the code that you use. It would also help if you could describe what you have tried so far to try and fix the problem.

avatar image NinjaDesigns · Dec 12, 2013 at 06:48 PM 0
Share

So the code is in an If Else statement. In the first If when I hit the key and Im inside a trigger box on the plane, these two lines: exitPoint.parent = jet.transform;

exitPoint.transform.localPosition = Vector3(-2.5,0,0);

Then in the second If after the Else, I have this one:

exitPoint.parent = doorTriggerLeft.transform;

So exitPoint is the empty GameObject thats child to the Jet. exitPoint is where i spawn when i exit the Jet.

Hope this explains it better.

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by robertbu · Dec 12, 2013 at 06:36 PM

You question is hard to understand. I think you are asking to have your character spawn upright even when the plane is an an odd angle, and that currently your character is taking his rotation from the plane. An easy solution is to use Quaternion.identity or Quaternion.Euler(someval,someval,someval) in the Instantiate(). These set the rotation to world coordinates, so the character will always be at the same rotation no matter what the orientation of the plane.

Another solution that might work better is to spawn the character at the planes rotation and then rotate the character so his head is facing up. So after your current spawn you can do:

 transform.up = Vector3.up;

Here is an alternate:

 transform.rotation = Quaternion.FromToRotation(transform.up, vector3.up) * transform.rotation;
Comment
Add comment · Show 1 · 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 NinjaDesigns · Dec 12, 2013 at 07:18 PM 0
Share

Thank you very much for your help.

$$anonymous$$uch appreciated

avatar image
0

Answer by 1337GameDev · Dec 12, 2013 at 06:44 PM

I would recommend "robertbu "'s answer, and set your rotation to a global value (identity) instead of the relative rotation (relative to the plane). When you instantiate, you are probably doing somehting similar to the following:

 Instantiate(playerPrefab, plane.posiiton, plane.rotation);


Instead, do this:

 Instantiate(playerPrefab, plane.position, Quaternion.identity);

This makes the player get instantiated with a rotation that is upright.

I would suggest using a lerp function to make the player slowly rotate to this value (to make it more realistic and not as snappy). I would also add some kind of offset from the plane for when you instantiate the player (or your player head could get stuck in the plane form being upright when the plane is at an angle or you are slightly inside of a wing or something). If you don't, you could get odd results.

Comment
Add comment · Show 1 · 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 NinjaDesigns · Dec 12, 2013 at 07:18 PM 0
Share

Thank you very much for your help.

$$anonymous$$uch appreciated

avatar image
0

Answer by NinjaDesigns · Dec 18, 2013 at 11:08 PM

So Im still having trouble with this, Im new and this flight script is far beyond the couple books I picked up on Java so bear with me.

Here is the whole enter/ exit code. It works, I can get in and out, change cameras from the character to the Jet, and have Flight controls. Im just having issues when I eject or press R/"Exit"

Im sure you guys gave me the right answers above, I just wasnt having much luck implementing them. Got some crazy results on some but Im that was me not your code. I hate to ask for so much help but everything I do either doesnt do anything or sends my character out to space.

Thanks for everyones help and patience. Its Christmas after all LOL. Happy Holidays.

function Start(){ CarCamera.enabled = false; } function Update(){

 if (Input.GetButtonUp("Enter")&& isPlayerVisible){
     // make player invisible and still standing
     player.gameObject.SetActiveRecursively(false);
     player.gameObject.active = false;
     // parent player to Exit Point. This is a trigger box
     player.parent = exitPoint.transform;
     player.transform.localPosition = Vector3(-1.5,0,0);
     // parent PlayerParent to car
     exitPoint.parent = car.transform;
     exitPoint.transform.localPosition = Vector3(-0.5,0,0);
     // Enable Car as controllabe object. Jet is the Prefab, Flight is the flying Script
     GameObject.Find("Jet").GetComponent(Flight).enabled=true;
     PlayerCamera.enabled = false;
     CarCamera.enabled = true;
     }
     else
     {
 if (Input.GetButtonUp("Exit")){
     // make character visible again
     player.gameObject.SetActiveRecursively(true);
     player.gameObject.active = true;   
     // unparent player from everything
     player.transform.parent = null;
     // parent Exit Point to door Trigger
     exitPoint.parent = doorTriggerLeft.transform;
     // disable car as controllable
     GameObject.Find("Jet").GetComponent(Flight).enabled=false;
     PlayerCamera.enabled = true;
     CarCamera.enabled = false;
     }   
 }

}

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

17 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Can this be rewitten to control axis locally instead of globally? 1 Answer

Is it possible to create a third Axis? 1 Answer

Animating around local rotation on Curves Editor 0 Answers

transform.LookAt on Y axis only? (C#) 3 Answers

Local Vectors not considering rotation somehow? 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