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 Bincredible · Oct 26, 2013 at 08:52 PM · rotationrigidbodyinstantiatevector3

I need help with rotation

Hey, I am making a game with a cannon that you can rotate to then shoot at cubes, Although when I change the rotation of the cannon, it just faces down and won't even rotate when I press the buttons I created. Any help would be good, here is my code :

 //var firePower : float;
 var ball : Transform;
 var ballPos : Transform;
 var timer : float;
 var addTime : boolean;
 var theBall;
 var move : boolean;
 var rotationX : int = 270;
 var barrel : Transform;
 
 function Update(){
 barrel.rotation.x = rotationX;
 if(!addTime){
     if(Input.GetKeyUp(KeyCode.Space)){
         fire();
         addTime = true;
     } 
 }
         if(move){
             theBall.rigidbody.AddForce(-Vector3.forward * 50);
         }
         
     if(addTime){
         timer += Time.deltaTime;
     }
     
     if(timer > 1){
     addTime = false;
         timer = 0;
         theBall = GameObject.Find("Sphere(Clone)");
         Destroy(theBall.gameObject);
     }
     
 } 
 
 function fire(){
     Instantiate(ball,ballPos.position,ballPos.rotation);
     move = true;
     theBall = GameObject.Find("Sphere(Clone)");
 }
 
 function OnGUI(){
     if(GUI.Button(Rect(10,10,100,30),"+")){
         rotationX += 3;
     }
     if(GUI.Button(Rect(10,40,100,30),"-")){
         rotationX -= 3;
     }
 }
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

Answer by robertbu · Oct 26, 2013 at 09:02 PM

Your problem is you are directly addressing 'rotation'. See my answer at the link below:

http://answers.unity3d.com/questions/563288/object-rotation-not-clamped-properly.html

For your specific use here, I suggest you use a relative rotation rather than trying to deal with euler angles. Something like:

 transform.Rotate(3,0,0);

http://docs.unity3d.com/Documentation/ScriptReference/Transform.Rotate.html

'X' rotation in particular have the issue mention in my first link where Unity will change representation. As long as you don't read Transform.eulerAngles, you should be okay, but you need to set all three axes at the same time. You should not set just a single axis. Transform.Rotate() will work.

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 Bincredible · Oct 27, 2013 at 10:47 AM 0
Share

Rotate() works fine for the ball spawn point, but when I fire the balls they still go straight no matter what rotation the spawn point is on, Here is an example. alt text

example.png (234.3 kB)
avatar image
0

Answer by Bincredible · Oct 27, 2013 at 11:13 AM

I fixed it! I had to change the AddForce to the spawn point's forward not Vector3.forward.

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.

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

Multiple Cars not working 1 Answer

Instantiating objects at position 1 Answer

Movement Relative to both Camera and XZ Plane 3 Answers

Objects Instantiating at wrong position 3 Answers

Rotation problem with spawning bullet 2 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