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 MrZalib · Feb 02, 2014 at 03:33 AM · c#rotatetranslate

Rotation and Translation problem

So I'm trying to make a Gyruss remake here and I'm working on the movement to get the ship to move in a circular pattern. I've run into a problem, here is an early version of my code.

 using UnityEngine;
 using System.Collections;
 
 public class PlayerControl : ShipClass
 {    
     public Transform shotStart;
     public PlayerShot shot;
 
     void FixedUpdate () 
     {
         int xAxisValue = (int) Input.GetAxis ("Horizontal");
         int yAxisValue = (int) Input.GetAxis ("Vertical");
         switch(xAxisValue)
         {
         case 1:
             transform.Rotate (0, 0, p_rotateSpeed);
             transform.Translate (1 * p_Speed * Time.deltaTime, 0, 0);
             break;
         case -1:
             transform.Rotate (0, 0, -p_rotateSpeed);
             transform.Translate (-1 * p_Speed * Time.deltaTime, 0, 0);
             break;
 
         default:
             break;
         }
 
         switch(yAxisValue)
         {
         case 1:
             transform.Translate (0, -1 * p_Speed * Time.deltaTime, 0);
             break;
 
         case -1:
             transform.Translate (0, 1 * p_Speed * Time.deltaTime, 0);
             break;
 
         default:
             break;
         }
 
         if (Input.GetButtonDown ("Fire2")) 
         {
             Debug.Log ("Fire2 pressed!");
             Instantiate(shot, shotStart.position, shotStart.rotation);
         }
 
 
         
         /*
          * 
          * Debug Purposes
          * 
          * 
         if(Input.GetKey("a"))
             transform.Translate (-1 * player.p_Speed * Time.deltaTime, 0, 0);
         if (Input.GetKey ("d"))
             transform.Translate (1 * player.p_Speed * Time.deltaTime, 0, 0);
         if (Input.GetKey ("s"))
             transform.Translate (0, -1 * player.p_Speed * Time.deltaTime, 0);
         if (Input.GetKey ("w"))
             transform.Translate (0, 1 * player.p_Speed * Time.deltaTime, 0);
 
         Debug.Log (Input.GetAxis ("Vertical"));
         */
     }
 }

Here's my problem. I start the game. And I'll move the ship to the left or right it doesn't really matter and everything works fine and dandy. When I decide to go back the other direction however and stop it at its starting position I notice that the ship has moved further up on the screen. I think that it is because that the rotate and translate statements don't happen at the same time but I have no clue of a workaround for this. Does anyone know of a way to fix this problem? Thanks in advance.

Comment
Add comment · Show 2
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 jg2115 · Feb 02, 2014 at 06:53 AM 0
Share

How is your camera following the ship? Is there a script or is the camera a child of the ship?

avatar image MrZalib · Feb 02, 2014 at 04:33 PM 0
Share

The camera is static in this game because its trying to simulate a 3D perspective. Google the game if you're not familiar with it. =) It's pretty awesome.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by gfoot · Feb 02, 2014 at 09:43 PM

I don't fully understand the motion you're trying to create here, but I think your problem is that when you move left or right you rotate before translating, whichever way you're moving. This means they are not inverses of each other.

The inverse of "rotate then translate" is "translate backwards then rotate backwards". So for example if you swapped lines 20 and 21, you might find the up/down drift goes away.

Comment
Add comment · Show 3 · 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 MrZalib · Feb 02, 2014 at 09:47 PM 0
Share

Gyruss is set up in which the player can move in a circular pattern around the entire screen. Whatever direction you push is where your little ship will go on the circle. I'm just trying to get the whole circular pattern of movement down. I'll try your answer though and see if it works. Thanks. =)

avatar image gfoot · Feb 02, 2014 at 09:55 PM 0
Share

So if you keep going left you want your ship to move in a full circle? That's also not going to work with your code how it is now, for similar reasons - it will spiral inwards.

You could use a rotation about the circle's centre point ins$$anonymous$$d of a translation, to partially fix that, but it will still drift a bit due to rounding errors.

avatar image MrZalib · Feb 02, 2014 at 10:02 PM 0
Share

Just tried it out on a quick run and it works like a charm! You sir have been most helpful! I have a different problem now but I think that requires a different question.

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

19 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

Related Questions

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Tube Shooter Movement Design Help 1 Answer

Porting to Windows: Translate problem 2 Answers

stop rotate around c# 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