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 /
  • Help Room /
avatar image
0
Question by binteimran11 · Sep 12, 2015 at 09:37 AM · rotationjavascriptgameobjectcube

How to rotate one cube from another cube?

I am completely new to unity as well as java script. Maybe my question makes you laugh but I want your help. I have 4 cubes and each cube has its own script file. I am using java script. I want to control rotation of cube1 from cube3 and vice versa. and also have to add add force in it. how can I do that? Thanks in advance!

Comment
Add comment · Show 1
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 hexagonius · Sep 12, 2015 at 08:54 PM 0
Share

create a public variable for a gameobject in the script and assign each I'd the two cubes the other one. in update, check their rotation and save the others current rotation. if the rotation differs from the saved one, rotate and save again.

for AddForce, I don't know what you mean. you already know the method name so with a rigidbody on the respective cube you can just call it.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Nirvana33 · Sep 12, 2015 at 09:12 PM

I'm not really sure if it works properly. I don't really know javascript. But it will help you.

First you need to create variables for cubes.

 public var cube1 : GameObject;
 public var cube2 : GameObject;
 public var cube3 : GameObject;

you'll assign the cubes from inspector panel. Don't forget.

To rotate you can simply use cube1.transform.Rotate(Vector3.right * Time.deltaTime); this will slowly rotate

 cube1.transform.rotation= Quaternion(90,0,0,0);

this will set the exact rotatiton of cube1(that you attached on inspector)

To use addForce

 cube1.GetComponent(Rigidbody).AddForce(transform.forward*300);



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 binteimran11 · Sep 13, 2015 at 10:40 AM 0
Share

Thank you very much for replying.. . with that I also want to rotate cube1 from the script file of cube3. That means if I want to rotate cube1 I have to call the function that I set in cube3.js file. How can I do that?

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

33 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 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

GameObject not looking at me.. 1 Answer

Camera Script remove a part. 0 Answers

how do i get my player get sucked into a gameobject 2 Answers

Rotat a GameObject and than shoot it in the New (x) direction 1 Answer

Undesired Angles with transform.Rotate(...) 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