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 NilsBalloon · Oct 06, 2012 at 12:19 AM · rotationmovementmeshfirst personballoon

Rotating object's xyz-axis but not its mesh

Hello! I´m making an air balloon simulator containg an air balloon and a first person camera in it.

I want my air balloons mesh to not rotate, but I want the balloon to move towards where the first person camera is pointing and it seem like the xyz-axis depends on the objects rotating. Is there any way to get around this?

My parts: Balloon, camera, part1, part2, part3

So how and where do I put my movement and mouse look scripts, and how do I solve this?

Thankful for an answer!

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 aldonaletto · Oct 06, 2012 at 01:17 PM

If I understood correctly what you want, my suggestion is to child the camera to the balloon and attach the MouseLook script to the camera, setting its Axes field to "Mouse X and Y" - this way you can look up/down/right/left with a single MouseLook. To move in the direction the camera is looking at, move the balloon in the camera's forward vector. If you want to control the vertical movement with the camera too, multiply the Y component by some factor between 0 and 1 - this way you can control how much the vertical camera swing affects the vertical movement.
If you need to detect collisions, add a CharacterController to the balloon and use Move; if not, simply use Translate (with Space.World specified). That's a basic movement script (attach it to the balloon):

var speed: float = 5.0; // how much the up/down camera movement influences the balloon vertical movement: var vSensitivity: float = 0.2;

function Update(){ // get the camera's forward direction: var dir = Camera.main.transform.forward; // apply part of the vertical cam direction to the vertical movement: dir.y = vSensitivity; // control forth/back movement with the Vertical axis: var move = dir.normalized Input.GetAxis("Vertical") speed Time.deltaTime; // Translate version: transform.Translate(move, Space.World); // CharacterController version: GetComponent(CharacterController).Move(move); }

NOTE: Remember to keep only one of the movement instructions (Translate or Move), deleting or commenting out the unused one.
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 NilsBalloon · Oct 08, 2012 at 01:21 PM 0
Share

Thank you! It works as I wanted!

avatar image
0

Answer by NowhereStudios · Oct 06, 2012 at 06:32 AM

If you are using FPSController, edit your MouseLook script on FPSController and on update function, add "Camera.current." prefix before all transform operations. Your Update function must be look like this:

 void Update ()
     {
         if (axes == RotationAxes.MouseXAndY)
         {
             float rotationX = Camera.current.transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;
             
             rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
             rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
             
             Camera.current.transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
         }
         else if (axes == RotationAxes.MouseX)
         {
             Camera.current.transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
         }
         else
         {
             rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
             rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
             
             Camera.current.transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
         }
     }

Goodluck ;)

Comment
Add comment · Show 4 · 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 NilsBalloon · Oct 06, 2012 at 10:49 AM 0
Share

Hi, Nowhere Studios!

When I modify as you told me, I got a nullReferenceException. Any clue of what to do? I tried to instantiate the BalloonCamera but I ended up recieving other errors (I´m quite new to C#, although not to java).

And what does current mean (it´s messy to google it)?

Please help!

avatar image NilsBalloon · Oct 06, 2012 at 01:35 PM 0
Share

Im using the first person controller from the standard assets (modified a bit)! I thought you meant the fps input controller, maybe you meant another script by fps controller?

avatar image NowhereStudios · Oct 06, 2012 at 06:35 PM 0
Share

Hi, I sent the code assu$$anonymous$$g you are using FPSController in Import Assets > FirstPersonController Prefab. If you do, then delete the capsule in it, Add Your baloon on the place of capsule, and finally Disable "Use Gravity" and "Jump" etc. to tune it for yourself. Finally replace the code block i said before.

avatar image NilsBalloon · Oct 07, 2012 at 11:38 PM 0
Share

Okey! But I get a nullReferenceException at $$anonymous$$ouseLookBalloon.Update () (at Assets/Scripts/$$anonymous$$ouseLookBalloon.cs:36). Any idea of how to solve it?

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

11 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

Related Questions

mesh colliders moving when i press play 1 Answer

How to make a square mesh and remove a part of it in real time? 0 Answers

Spin while moving 2 Answers

How do i make it more horizontally with no rotation? 1 Answer

Isometric + Orthographic Player Movement 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