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 Mint92 · Dec 01, 2013 at 05:33 PM · c#rotationjavascriptmouseyaxis

Rotate object with mouse

alt text

probably a better idea on what I want, Ive it to spawn the bullets, but i just need it to rotate on a fixed position like the image is showing. Someone guide me on how to do this please

untitled.png (293.3 kB)
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 diegzumillo · Dec 01, 2013 at 05:48 PM 0
Share

I think you meant Z axis, right?

avatar image Mint92 · Dec 01, 2013 at 06:47 PM 0
Share

Yes Z sorry

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Dec 01, 2013 at 05:58 PM

There are many different ways depending on game. Here is one way:

 #pragma strict
  
 var speed = 0.5;
  
 function Update () {
      transform.Rotate(0.0, 0.0, -Input.GetAxis("Horizontal") * speed);
 }

To use this script, go to Project Settings > Input and make sure that the entry for 'Horizontal' has the 'Type' set to 'Mouse Movement'. In addition, if you plan on using multiple different screen resolutions, you will likely need to scale 'speed' as appropriate to the resolution.

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 Mint92 · Dec 01, 2013 at 06:52 PM 0
Share

Ive done it how told me to, but its only rotating the object, I need it so it goes left and right and rotate on the axis in a fixed position. something like this alt text

ipod_parachute.jpg (11.1 kB)
avatar image robertbu · Dec 01, 2013 at 06:56 PM 0
Share

Your actual question states, "but i just need it to rotate on a fixed position." So now there is an issue about how to interpret the mouse movement. Should the movement push the tank left and right, or should it rotate the tank. Or is there some sort of key or switch that changes between the two?

avatar image Mint92 · Dec 01, 2013 at 07:03 PM 0
Share

sorry i just realised that my title isnt the best description to what i want. the only object that should be moving is the turret

avatar image Mint92 · Dec 01, 2013 at 07:05 PM 0
Share

http://www.youtube.com/watch?v=H3i0HLCrdSk its not the best example

avatar image robertbu · Dec 01, 2013 at 07:13 PM 0
Share

I still don't completely understand. I change my code above so that it now rotates around the 'z' axis. In the video, the turret does not move left and right, just the gun angles left and right. The code above will do that. If you are trying to mix movement and rotation (i.e. the gave above mixed with Alien Invaders), then you will have to specify how the inputs are done.

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

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

Flip over an object (smooth transition) 3 Answers

Character Not Rotating 0 Answers

Rotate object following mouse movement. Object jumps/ flips 1 Answer

[C#]Angle of shooting equale to mouse direction 1 Answer

Vertical mouse input inverted when player is turned around 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