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 marshin77 · Apr 08, 2013 at 05:12 AM · rotationdirectionfacingship

making my space ship rotate then move.

so i am trying to make the space ship the player rotate in 90 degree increments then move if it is not already facing in the direction it is told to go.

 #pragma strict
  var player : GameObject;
 var health : int = 100;
 var speed : int = 1;
 var collided_with : GameObject;
 var alignedL : boolean = false;
 function Start () {

 }
 
 function Update () {
 
  if(Input.GetAxis("Horizontal") >0){
     transform.Translate(Vector3(1 * speed * Time.deltaTime,0,0));
   
   }
   if(Input.GetAxis("Horizontal") <0){
     transform.Translate(Vector3(-1 * speed * Time.deltaTime,0,0));
   }
   if(Input.GetAxis("Vertical") >0 ){
     transform.Translate(Vector3(0,1 * speed * Time.deltaTime,0));
   
   }
    if(Input.GetAxis("Vertical") <0 ){
     transform.Translate(Vector3(0,-1 * speed * Time.deltaTime,0));
   
   
   }
 
         
 
   
 }
 
 function OnCollisionEnter(col : Collision) {
 
 collided_with = col.gameObject;
 
 
 
 }

i don't just want the answer i would prefer a detailed explenation.

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 BDP1 · Apr 08, 2013 at 07:58 PM 0
Share

From what I can tell, you never really rotate. So I'm assu$$anonymous$$g you don't know how? Also, you are only translating on the X and Y axis, so this is a 2d game right?

I am a newb but feel like I may be able to help on this one.

When I made a Tetris clone, I encountered a similar situation. I set up a "pivot point" on my blocks and made it the block parent. Whenever I got instructions to rotate the bock from the player, I just rotated the block around the pivot point using transform.RotateAround.

As for a detailed explanation, maybe some clarification would help before I say anything more. Let me know if I am on the right track.

avatar image marshin77 · Apr 08, 2013 at 08:13 PM 0
Share

yah that's on the right path i knew transform.rotate i just couldn't figure out how to implement it in a way that worked so it would rotated till it faced the direction it needed to move then begin to move move forward.

avatar image dukester · Apr 08, 2013 at 11:11 PM 0
Share

Before each "transform.Translate..." add

"transform.localEulerAngles = Vector3(0,0,Z);"

For the Z component of the vector you need 0,90,180 and 270. Just experiment to see which goes where.

avatar image marshin77 · Apr 08, 2013 at 11:22 PM 0
Share

ill see if it works thanks

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

13 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

Related Questions

How to snap a model to the direction being moved in, without also rotating the character controller 3 Answers

Control object yaw by two axis 1 Answer

Straighten out camera rotation 1 Answer

Getting the face direction 2 Answers

rotate vector around local axis 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