Search Unity

Galaga Clone

Discussion in 'Editor & General Support' started by geekaboard, Mar 23, 2010.

  1. geekaboard

    geekaboard

    Joined:
    Mar 23, 2010
    Posts:
    2
    I am trying to create a game similar to Galaga, but I do not know how to make the enemies follow curved and circular paths.
    I already tried the "Spline Script" but it does not exactly work the way I want. The enemies tend to accelerate when one segment is longer than other.

    I hope that someone can give me some ideas, because I have been banging my head for more than a week.
     

    Attached Files:

  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Hi, welcome to the forum!

    It is a basic property of splines that the interpolation changes speed as you progress through the curve, and it is difficult to counteract this effect. I've just had a brief look at an online Galaga recreation and it appears that the enemies move only in straight lines or in circles of different radius. You can use transform.RotateAround to make an object orbit around a point in space like this. For the enemies, the centre of the orbit will be a point on a line directly to the left or right of the current position (this line can be accessed using transform.right). The centre will be at a distance equal to the desired radius of the circle.

    To get a uniform speed between the straight line motion and the orbiting, you need to convert the linear speed into an angular speed, which you can do with this expression:-
    Code (csharp):
    1. var angularSpeed: float = linearSpeed / circRadius * Mathf.Rad2Deg;
    This is in degrees per second, so you would multiply this value by Time.deltaTime to get the number of degrees to rotate in a given frame update.
     
  3. geekaboard

    geekaboard

    Joined:
    Mar 23, 2010
    Posts:
    2
    Thanks Andee, I really needed that solution because I was stuck for a while.

    Thank you very much, I will keep everyone updated when I finish my Galaga clone.
     
  4. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Can you `draw with the mouse` while recording the mouse movements into an array or something, and then just play back the movements? You can figure out the angle of rotation of the ship image based on two steps of movement. This way you can then decide whether you want the ships to move fast or slow or speedup or whatever by moving your mouse faster. Then you can just play back the recorded motion.
     
  5. caseyboundless

    caseyboundless

    Joined:
    Oct 17, 2011
    Posts:
    590
    could you go into a little bit more detail please. I'm pretty new to programming and trying to do something similar. Here's my script.


    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class spin : MonoBehaviour {
    5.     float linearSpeed = 1.0f;
    6.     float circRadius = 3.14f;
    7.    
    8.    
    9.    
    10.     void Start()
    11.     {
    12.    
    13.          float angularSpeed = linearSpeed / circRadius * Mathf.Rad2Deg;
    14.        
    15.     }
    16.    
    17.    
    18.    
    19.    
    20.    
    21.    
    22.    
    23.    
    24.    
    25.    
    26.    
    27.    
    28.    
    29.     void Update()
    30.     {
    31.         transform.RotateAroundLocal(Vector3.forward,  0 * Time.deltaTime);
    32.     transform.RotateAround(Vector3.zero, Vector3.forward, 20 * Time.deltaTime);
    33.     }
    34.  
    35.  
    36.  
    37.  
    38. }



    When I put angularSpeed after Time.deltaTime in the rotation method i get errors.