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 LEMONVirus99 · Jul 16, 2013 at 03:04 PM · javascript

Manipulate gameobjects, pick up & rotate

I am planning to have a gameobject that can be picked up by a mouse click and when the mouse is released, the object will fall. Also, i want to manipulate the object by pressing a key (X) to rotate the object clockwise (on the Z axis) with a changeable speed in the inspector. So far in the script i have set the axis as it is a 2d game

 function Update()
 {
     var v = Input.GetAxisRaw("Vertical");    // v = -1 for down and +1 for up
     var h = Input.GetAxisRaw("Horizontal");    // h = -1 for left and +1 for right input
     if ( Input.GetKeyDown("X") )
     {
     //rotate
     }

Many thanks

Comment
Add comment · Show 4
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 robertbu · Jul 16, 2013 at 03:07 PM 1
Share
 How about transform.Rotate(0.0, speed * Time.deltaTime, 0.0);

where 'speed' is a variable you declare and initialize to degrees per second you want it to rotate.

Also you probably want Input.Get$$anonymous$$ey() rather than Input.Get$$anonymous$$eyDown(). Get$$anonymous$$eyDown() only returns 'true' for a single frame. With Get$$anonymous$$ey() your object will rotate as long as the key is held down.

avatar image LEMONVirus99 · Jul 16, 2013 at 03:32 PM 0
Share

so could i use Input.Get$$anonymous$$ey() for the mouse click and X button? as i don't want it to be a toggle. And how would i structure this code? Say if my object was called 'Block 1' would i need to set a trigger so when the button was pressed the code will activate for said object?

avatar image robertbu · Jul 16, 2013 at 04:13 PM 0
Share

There are lots of posts for drag and drop in Unity Answers. I'd start this by searching the list and looking at scripts. GetAxis() is not a good way to do dragging. GetAxis()/GetAxisRaw() return values in the range of 0.0 and 1.0, so it will be impossible to keep the object and the mouse aligned. Take a look at On$$anonymous$$ouseDown() and On$$anonymous$$ouseDrag() as ways to capture when a specific object has been click on. Another approach uses Physics.Raycast(). Depending on the nature of your game, dragging and dropping can be fairly easy to fairly difficult.

avatar image robertbu · Jul 16, 2013 at 04:15 PM 0
Share

You might take a look at the DragObject script in the Unity Wiki:

http://wiki.unity3d.com/index.php?title=DragObject

If the object you want to drag have rigidbodies, you can use the DragRigidbody.js script. From Assets, select Import Package/Scripts. The DragRigidbody script will be one of the scripts imported.

0 Replies

· Add your reply
  • Sort: 

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

15 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

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

press e to speek -1 Answers

Atmosphere sounds triggered by invisible blocks? (JS) 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