Search Unity

Ludum Dare 48 Work In Progress Games!

Discussion in 'Works In Progress - Archive' started by Arowx, Apr 20, 2012.

  1. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Hi thought it would be handy to setup a thread where Unity dev's taking part in this weekends Ludum Dare #23 challenge could post quick WIP shots or links to games that might need some testing/feedback.

    Hope I have time to use this, b4n off to warm up!
     
  2. XavLar

    XavLar

    Joined:
    Feb 14, 2012
    Posts:
    143
    I can't wait to see the games people make! I've started to work on a game myself (not in the Ludum Dare) along with the competition :)
     
  3. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
  4. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    WIP ScreenShot 01



    Not sure where this is going but it's a start!
     
  5. henry96

    henry96

    Joined:
    Sep 28, 2011
    Posts:
    582
    It looks good , man!
     
  6. joshimoo

    joshimoo

    Joined:
    Jun 23, 2011
    Posts:
    266
  7. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194


    WIP Screenshot 2
     
  8. joshimoo

    joshimoo

    Joined:
    Jun 23, 2011
    Posts:
    266
    Spend the Last 4 Hours trying to fix a bug with my rotation code, unfortunately not successful.
    Probably because my Math Background is lacking.

    If anybody knows what I am doing wrong, please share with me.
    Thank you for your time.

    Demo:
    http://dl.dropbox.com/u/65310012/LD23/WebPlayer.html
    - Press Left Mouse Button to place the Target at the flattened MousePosition

    Hierachy:
    - Player (Get's input and calls the appropriate Methods on the Ship)
    - Player/Ship (Turns on Z towards mouse)
    - Player/Ship/Gun (Turns on Z towards towards MyTarget)
    - Player/MyTarget (Get's placed on Fire1 or Fire2)

    Code:
    Code (csharp):
    1.  
    2.  
    3.     // Tried Update as well, did not work either.
    4.     void LateUpdate()
    5.     {
    6.         // Lookat Target
    7.         Target(myTarget.position);
    8.     }
    9.  
    10.     // TODO: Wasted 4 Hours trying to get the rotation code working, I failed.
    11.     void Target(Vector3 targetPosition)
    12.     {
    13.         var dir = targetPosition - transform.position;
    14.         float angle = Vector3.Angle(transform.up, dir);
    15.  
    16.         // Ignore small differences, has helped the jerkiness a bit
    17.         if (Mathf.Abs(angle) > 5.0f)
    18.         {
    19.             Debug.Log("Angle: " + angle);
    20.             transform.Rotate(transform.forward, angle);
    21.         }
    22.     }
    23.  
     
    Last edited: Apr 22, 2012
  9. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    This should do the trick, includes smoothing as well. p1 is source angle (could be your current angle of turret in degrees) and p2 is your destination angle to rotate to.

    You'll find the correct angle by using Atan2, and then convert to degrees if required. Hope that helps. Or use a built in unity method to get the correct angle you should be pointing to and plug that in (as degrees) to p2. Set t to a number between 0 and 1 (lower means softer rotation).


    Code (csharp):
    1. static function TweenAngle( p1:float , p2:float , t:float)
    2. {
    3.     var aDif:float = p2-p1;
    4.    
    5.     if (aDif >= 180.0)
    6.     {
    7.         aDif -= 360.0;
    8.     }
    9.     else
    10.     {
    11.         if (aDif <= -180.0)
    12.         {
    13.             aDif += 360.0;
    14.         }
    15.     }
    16.     return p1 + t * aDif;
    17. }

    The problem with your code is it isn't accounting for the numerical shift between 359 and 0 I believe (didn't check it too carefully). Good luck and ask again if you need help finding the angle to plug into p2 (you should have that).
     
  10. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    And here's a quick angle function in 2D which should do the job for finding p2.

    Code (csharp):
    1. static function Angle2D(x1:float, y1:float, x2:float, y2:float)
    2. {
    3.     return Mathf.Atan2(y2-y1, x2-x1)*Mathf.Rad2Deg;
    4. }
    (returns resulting angle between two points, in degrees).
     
  11. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Yes I know it's one of those rare times I post code help coz it's ludum dare and people need to go for it :D

    Btw the t parameter is how soft you'd like it with 1 snapping to target at top speed.
     
  12. Heu

    Heu

    Joined:
    Feb 13, 2012
    Posts:
    349
    I got a game right here with 13 levels out of the 25 i will try to have.
    It's a simple platformer with some puzzling, but overall extremely basic.

    Webplayer Right Here.
     
  13. elvis75k

    elvis75k

    Joined:
    Feb 5, 2011
    Posts:
    24
    Here i am! I'll do better next time.. link to the WebPlayer
     
  14. joshimoo

    joshimoo

    Joined:
    Jun 23, 2011
    Posts:
    266

    I spend another 3 Hours trying different things to get it to work.
    Finally got it to work just now, more luck than anything.
    But I am ashamed to say, I have no Idea what's going on behind the scenes there.

    Once Ludum Dare is over, I will need to grab a math book and start studying.
    Any recommendations?

    Thanks for the help, it's appreciated. ;)

    The Final Code:
    Code (csharp):
    1.  
    2.  
    3.     // Get the Angle Beetwen 2 Points in 2D Space
    4.     static float Angle2D(float x1, float y1, float x2, float y2)
    5.     {
    6.         // TODO: Read up on Atan2
    7.         //return Mathf.Atan2(y2 - y1, x2 - x1) * Mathf.Rad2Deg;
    8.         return -Mathf.Atan2(x2 - x1, y2 - y1) * Mathf.Rad2Deg; // HACK: <-- This one Works, but why?
    9.         //return Mathf.Atan2(x1 - x2, y1 - y2) * Mathf.Rad2Deg;
    10.     }
    11.  
    12.     void Target3(Vector3 targetPosition)
    13.     {
    14.         // Calculate Angle to Target
    15.         Vector2 fromPos = myTransform.position;
    16.         Vector2 toPos = targetPosition;
    17.         float targetAngle = Angle2D(fromPos.x, fromPos.y, toPos.x, toPos.y);
    18.  
    19.         // Get the Current Z Rotation Angle
    20.         float currentAngle = myTransform.rotation.eulerAngles.z;
    21.         float uniAngle = Vector2.Angle(fromPos, toPos);
    22.         Debug.Log("CurrentAngle: " + currentAngle + " TargetAngle: " + targetAngle + " UniAngle: " + uniAngle + " P2-P1: " + (targetAngle - currentAngle) + " P1-P2: " + (currentAngle - targetAngle));
    23.  
    24.         // Tween Beetwen them
    25.         float lerpValue = 1.0f;
    26.         float smoothedAngle = TweenAngle(currentAngle, targetAngle, lerpValue);
    27.  
    28.         // Set Rotation
    29.         myTransform.rotation = Quaternion.Euler(0, 0, smoothedAngle);
    30.         //myTransform.localRotation = Quaternion.Euler(0, 0, smoothedAngle);
    31.     }
    32.  
     
    Last edited: Apr 22, 2012
  15. henry96

    henry96

    Joined:
    Sep 28, 2011
    Posts:
    582
    I've been working on my game for about 6 or 7 hours. Here's what it looks like:

    $screenshot01.jpg

    Still got a lot of things to do.
     
  16. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    How long is there to go? i just started :p
     
  17. henry96

    henry96

    Joined:
    Sep 28, 2011
    Posts:
    582
    It's still a long way to go. This is level 1. I plan to have 5 levels. But well, I got level 1 almost done. By the way you join Compo or Jam?
     
  18. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    Compo :D This is a screenshot so far the idea was that you have to stay in the light but now im thinking that the planet makes space ships and you have to shoot them :p

     
  19. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    Last edited: Apr 22, 2012
  20. Heu

    Heu

    Joined:
    Feb 13, 2012
    Posts:
    349
    If you mean submit it, go here http://ludumdare.com/compo/ and there should be a
    ->SUBMIT HERE<- button you can click on. Dont forget to include your source code

    Rules can be found here
    http://www.ludumdare.com/compo/rules/
     
  21. henry96

    henry96

    Joined:
    Sep 28, 2011
    Posts:
    582
    There is still one hour left for compo submission! I join jam though!
     
  22. henry96

    henry96

    Joined:
    Sep 28, 2011
    Posts:
    582
    Now the Ludum Dare is closed for voting. Who else joined the contest?
     
  23. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
  24. henry96

    henry96

    Joined:
    Sep 28, 2011
    Posts:
    582
    what! look like I missed the fun. time to join