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 Tekksin · Nov 05, 2013 at 06:46 PM · rotationmovementrigidbodytranslateforward

Trying to make a Projectile Rotate and Move Forward..

I'm trying to make a projectile move forward and rotate as it does so.

Here is the code I currently have for the projectile's movement:

 function Update () {
     if(travelRight){
             transform.Translate(Vector3(-speed * Time.deltaTime * 2, 0, 0));
             transform.Rotate(Vector3(0, 0, 20));
             Destroy(gameObject, 3);
         }
     if(!travelRight){
             transform.Translate(Vector3(speed * Time.deltaTime * 2, 0, 0));
             Destroy(gameObject, 3);
         }
 
 }

In the "if(travelRight){" statement, the projectile just instantiates and rotates in place.

Whereas in the "if(!travelRight){" statement, the object obviously just moves to the left.

I want the projectile to travel right or left, but rotate as it does so, and if I add any rotate function (so far) the projectile rotates and doesn't move forward. And if it does make any movement forward, it's not a local rotation. It ends up being a circular, global-like rotation. Does anybody know how to fix this? I've tried so many things and keep failing :( any help would be greatly appreciated!! Thanks

it's a rigidbody, btw.

EDIT: I have since just made a sprite to fake the look of rotation, but knowing this information would still be useful. 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 Starwalker · Nov 05, 2013 at 07:43 PM 0
Share

Have you tried: transform.Rotate(Vector3.up * Time.deltaTime, Space.World);

the transform.Translate / Rotate would act differently depending to what co-ordinate system you want them to translate / rotate against.. just wondering if you might already have tried Space.world as a parameter.

avatar image Starwalker · Nov 05, 2013 at 07:46 PM 0
Share

Another fyi: if 'travelRight' becomes true even for a single frame, since its running on a "UPDATE" call, your translate will be all screwed. So make sure, when an object has started moving in one direction, keep it moving right till it reaches its destination.

avatar image Tekksin · Nov 05, 2013 at 07:51 PM 0
Share

tried transform.Rotate(Vector3.up * Time.deltaTime, Space.World); and it didn't do anything. It might be the moving right problem you mentioned, but I have no idea how to fix that :( what do i have to write to say "keep moving til you reach the destination"?

avatar image Starwalker · Nov 05, 2013 at 07:55 PM 0
Share

You need a trigger at the start and destination, which is either set off/reset by collision detection or Input, and the setting of the "travelRight" should happen outside the Update function, only ONCE, not in every frame. travelRight is a even monitor in this case, for what its doing.. and events trigger once, and then something has to reset it.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by MadMapp · Nov 05, 2013 at 08:49 PM

 var X: int;
 var Y:int;
 var Z: int;
 
 var rotationsPerMinute : float = 10.0;
 function Update()
 {
     transform.Rotate(X,Y,Z*rotationsPerMinute*Time.deltaTime,0);
 }

attatch this to the object you want to spin, have a second object an empty, atatch a script to make it move on instantiation, attatch you rotating object as a child object, what your doing presently is rotating while moving forward which will produce a circle

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

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

look at movedirection 1 Answer

Understanding Space.World and Space.Self: Character changing movement direction 1 Answer

Prevent Rigidbody From Rotating 3 Answers

Rotating my character only while moving in a 2D plane 3 Answers

Drawbacks of Moving Rigidbody by transform.translate 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