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 03, 2014 at 01:02 AM · c#rotatetranslate2d-gameplaydesign

Tube Shooter Movement Design Help

So I'm making a 2D "Tube Shooter". If you're not sure what that is look up Gyruss. I'm having a bit of a problem with my implementation of the circular pattern of movement.

I've decided to implement the movement using a combination of rotation and translation functions. This makes the ship appear like it is moving in a circular pattern while keeping the front of the ship pointed to the center. I feel like I may be taking the hard road here in implementation of this feature of the game. Here is my code for control.

 using UnityEngine;
 using System.Collections;
 
 public class PlayerControl : ShipClass
 {    
     public Transform shotStart;
     public PlayerShot shot;
 
     void FixedUpdate () 
     {
 
         //Movement Control
         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.Translate (-1 * p_Speed * Time.deltaTime, 0, 0);
             transform.Rotate (0, 0, -p_rotateSpeed);
             break;
 
         default:
             break;
         }
 
         //Y axis isn't implemented currently as I'm just testing out moving left and right.
         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;
         }
 
 
         //Firing mechanism
         /*
         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"));
         */
     }
 }

My problem comes from the way the ship moves. It doesn't move in a perfect circle. More specifically when the ship moves from its starting position to the top of the screen it has shifted slightly on the X axis when I want it to end up in the same position just a direct inverse of the Y starting position.

Here are my questions. Is there a better way to implement this? If not is there something I'm missing that makes the ship act like this?

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

1 Reply

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

Answer by robertbu · Feb 03, 2014 at 01:23 AM

You should check into Transform.RotateAround(). If you have the camera with rotation (0,0,0) and position (0,0,x), getting Gyruss type functionality is as simple as:

 using UnityEngine;
 using System.Collections;
 
 public class Control : MonoBehaviour {
 
     public float rotateSpeed = 8.0f;
 
     void FixedUpdate() {
         transform.RotateAround(Vector3.zero, Vector3.forward, rotateSpeed * Input.GetAxis ("Horizontal"));
     }
 }

You could also do the rotation in Update() instead of FixedUpdate() and scale the rotation by Time.deltaTime.

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 03, 2014 at 04:21 AM 0
Share

Hey you know what I hadn't thought about rotating around the center object. Someone else suggested using FixedUpdate() over Update() because of the 2D collision. Is there a huge difference? Thanks you've been a huge help!

avatar image robertbu · Feb 03, 2014 at 04:30 AM 0
Share

No huge difference, though it may not buy you any help with the collisions.

http://answers.unity3d.com/questions/10993/whats-the-difference-between-update-and-fixedupdat.html

avatar image MrZalib · Feb 03, 2014 at 04:37 AM 0
Share

You sir, are a saint right now. Thank you so much!

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

18 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

Related Questions

Multiple Cars not working 1 Answer

An OS design issue: File types associated with their appropriate programs 1 Answer

Rotation and Translation problem 1 Answer

Distribute terrain in zones 3 Answers

Rotating while rotating? 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