Search Unity

I want to make game based on concept of Zuma...

Discussion in 'Editor & General Support' started by Meher21188, Jan 12, 2015.

  1. Meher21188

    Meher21188

    Joined:
    Jan 8, 2015
    Posts:
    5
    I want to make game based on concept of Zuma...Whenever i fire ball towards ballset which is moving towards centre destination point, it does not stick there to continue path.But it get bounce.Please help me that i am noob in unity...
     
    olynn_ likes this.
  2. Graham-Dunnett

    Graham-Dunnett

    Unity Technologies

    Joined:
    Jun 2, 2009
    Posts:
    4,288
  3. Kishorprajapati007

    Kishorprajapati007

    Joined:
    Jan 12, 2015
    Posts:
    6
    hahaha..

    Yes, i think so..
     
  4. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,000
    I would suggest not using physics directly and just using math. I was building one about a month ago, and physics can be a little unpredictable. By using paths and controls and basically programmatically animating all the action, you can get pretty nice results.
    Here is my experiment :

    (sorry, its a bit dark, the art and stage is still heavily in progress. ;)
     
  5. Meher21188

    Meher21188

    Joined:
    Jan 8, 2015
    Posts:
    5
    Thanks friend.Really gr8 video and can understand you worked harder.I would thankful if you help me to get code for spawning of ballset properly.:)
     
  6. Kishorprajapati007

    Kishorprajapati007

    Joined:
    Jan 12, 2015
    Posts:
    6
    Woow its a great game made by you, @zombiegorilla

    It would be great if you will help us to make a game like yours.

    Thanks.
     
  7. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,000
    I'll be happy to answer specific questions. Like I said, I would recommend using paths/splines and controlling the motion programmatically instead of using physics, it's much less overhead and much more control.
    Here you can see the pathing setup that I use for the balls. I use DOTween to determine the distance, and move them along based on distance(size) of the balls.
    Screen Shot 2015-01-13 at 10.45.33 PM.png

    Here is a look from the editor.
     
    Cromfeli likes this.
  8. Meher21188

    Meher21188

    Joined:
    Jan 8, 2015
    Posts:
    5
    I want to know that how ball get place near the target ball-set. Also facing problem while generating ballset .Can you provide me code for ball spawning and shooting.If possible?:confused:
     
  9. Kishorprajapati007

    Kishorprajapati007

    Joined:
    Jan 12, 2015
    Posts:
    6
    Hi zombiegorilla,

    I had attached a screen shot, where i am facing a problem. I want to generate balls from my starting path in a random colors with the rolling effect.

    Plz Help
    Thanks,
     

    Attached Files:

  10. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,000
    I won't provide any code, but I'll certainly share what I am doing conceptually. What problems are you having creating the balls? I am doing nothing fancy there, I just instantiate them from a random set of prefabs. To keep things running smooth, I pre-generate all the balls (and a small pool for the ones being fired). That prevents any slow down or frame drops.

    For the path, I use waypoints. (a series of empty transforms) You can use either iTween or DOTween traverse the path. I prefer DOTween. I create a new tweener each of balls (that is stopped initially). I then just .Goto on the tweens to move them along path at specific points. (Simple Waypoint System also works well, as you can just get a normalized position on a given path.). All the balls are in an array, that is compressed (when balls are removed) and expanded (when balls are added). It actually works pretty much automatically because I bind the location to the array index. So when say 4 balls are removed, the array compressed the 5th ball now is bound the same location that the first was, it will roll quickly back to that place.

    The rolling is essentially faked. I align the ball's forward axis to the path, and the mesh and effects are nested in side the main transform. I rotate the inner part based on percentage of location. I actually spin them a little faster than they would in reality. (1.2* the actual rotation). It just looks a little more dynamic.

    Shooting is done pretty much the normal way, translated along the forward axis of the cannon,
     
  11. Kishorprajapati007

    Kishorprajapati007

    Joined:
    Jan 12, 2015
    Posts:
    6
    Thank You for the help,
     
  12. Meher21188

    Meher21188

    Joined:
    Jan 8, 2015
    Posts:
    5
    Hi zombiegorilla,
    Thanks for help.I am facing problem while spawning ball set and ball movement. I have created prefab of 'Ball' which is sphere gameobject.I have used iTween for pathfinding. When i tried to spawn 10 balls using 'Ball' prefab clone.But unable to add ballmovement (script) for path towards destination.Please help me out.Here attaching file for more info.
     

    Attached Files:

    • Game.rar
      File size:
      421.2 KB
      Views:
      386
  13. Meher21188

    Meher21188

    Joined:
    Jan 8, 2015
    Posts:
    5
    Does spawned ballset prefab contain rigidbody component?your help is highly appreciated.
     
  14. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,000
    I don't use iTween, I don't think it has the same features for pathing that DOTween does. The big one be being constant speed traversing a path. When I experimented with it, the speed was constant between nodes, so if nodes A and B are very close, and C is very far, it will appear that things travel between A and B much slower. At the time when I looked for a clean pre-rolled solution for this SWS (Simple Way Point System) was the best option and had the cleanest pathing. After using it I realized that they were leveraging HOTween (at the time), which introduced me to the never-ending joy of DOTween.

    Yes, the balls do contain a rigidbody, BUT, it is not used for physics at all, just for collision detection and for the beam to bounce of off. All motion is done by moving the objects directly.
     
  15. oocast

    oocast

    Joined:
    Sep 4, 2015
    Posts:
    1
    Hi zombiegorilla,
    Do know how to reuse a created Tween? I tried create a Tween for each ball, and the game gets incredibly lagging. Since every ball follows the same path, is there a way to share the tween? Or can you tell how you made the game smooth while each ball moves along the path?
     
  16. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,000
    I only create one tween. It essentially has an empty on it that serves as a proxy. As I move each ball I move that proxy to the ball, normalized position on the path and get the new position and look ahead to keep it aligned. This way I only have one path, and the balls have individual control over their own speed and location.
    Though with each group the in sequence base that on the ball in front. That allows all balls behind a insert to slow down or if there is a gap balls behind that gap move faster to catch up.
     
  17. rurupoodle

    rurupoodle

    Joined:
    Apr 1, 2016
    Posts:
    5
    hi @zombiegorilla. can i ask a question about the pathing movement?

    how do you keep the speed constant over curve and straight lines?

    thanks
     
  18. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,000
    Dotween handles that. That is one of the many reasons I like that library. ;). I move the balls manually, converting the distance to a percentage of the path and getting the location from the path. Some of the other tweeners don't do consistant distance, iTween didn't that is why I looked for a better solution.
     
  19. rurupoodle

    rurupoodle

    Joined:
    Apr 1, 2016
    Posts:
    5
    wow that's a fast reply. Thanks for the time! Well i'm considering to get the Dotween pro.

    thanks again!
     
  20. Yowling-Cat-Games

    Yowling-Cat-Games

    Joined:
    Dec 11, 2014
    Posts:
    37
    @zombiegorilla what version of Unity do you currently use or recommend... just curious ;)

    Thanks
     
  21. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,000
    I'm on the latest release for current/new projects. 5.4.2f2.
     
  22. ChaosA

    ChaosA

    Joined:
    Nov 1, 2016
    Posts:
    1
    Hi @zombiegorilla ,
    I'm new to unity and even newer to Tweening, is there any tutorial that you can point me towards to help me learn how to use tweens properly. Before coming across this post, I tried making a 2d zuma game with balls moving using leantweens but i had no idea how to properly use them so i could not make new balls start tweening from the position where they join the path instead of the origin point of the path i created.

    Edit: While I did use LeanTweens before, if using a different tweening system like DOTweens makes it easier I will use them.
     
    Last edited: Jul 10, 2017
  23. ryo1102

    ryo1102

    Joined:
    Mar 18, 2016
    Posts:
    3
    Hi @zombiegorilla
    I want after shooting and destroying the ball.
    Then check that if the balls can run in the opposite direction, they run backwards, otherwise they stand still.
    Finally, when the ball is running to the ball to stand still, then run again.
    Can you give me any suggestions?
    Thank you!
     
  24. armnotstrong

    armnotstrong

    Joined:
    Mar 3, 2017
    Posts:
    18
    Hi, @zombiegorilla Do you mean to implement this that you have a list of the balls and move the balls according to the position of previous ones not according the path?

    I mean how we determine how much distance we should move the ball (forward and backwards when balls removed)
     
  25. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,000
    I use both. In my list each ball knows is position ( both normalized and unit distance. ). To simplify things, each ball is 1u in diameter. So along the path, if there is no gap, the are 1f apart from each other. When I move each ball, the distance between it and the one in front (assuming it isn't ball 0), is >1f I speed it up to close the gap. When I insert, I determine between which balls it goes and speed up the front balls to move .5 and back balls to move -.5. And do a quick tween to move new ball into that place.
     
  26. armnotstrong

    armnotstrong

    Joined:
    Mar 3, 2017
    Posts:
    18
    Thanks for quick reply @zombiegorilla, If I got you right you have two tweeners on each ball like this:



    But I am confused is that:

    - do you use the DoTween.DoPath() function to move balls along the path or do a Dotween.DoMove() repeatly through each waypoint manually?

    - If there are two tween functioning at the same time, how could they mix up together?
    + like if to catch up with the front ball we should move a gap 0.5 with the fix tween(blue one), but there is also a path tween says we should move 1.0f per second to keep the sequence moving, So the total speed should be 1.5?
    + how to determine when we should stop the fix tween(blue one)

    Following image shows what I have achieved now, red balls are shot by cannon, but when inserting the ball to the sequence, I just can't find the right place to insert :-(

     
    Last edited: Sep 14, 2017
  27. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,000
    No, there is only one tween, for the first ball. (actually an empty transform that the balls follow). All the other balls are just updated each frame with new positions. (lead ball position + (ball number * 1f)) Each ball knows where it should be, and by how much it should move. So if there is a gap -- ball 5 is now supposed it be in the ball 2 position, I use a smooth damp to move it overtime to where it should be. (the balls behind, just follow the one ahead, so the move along. The only time I use another tween is to move a new ball into location.

    For insertion, it is just based on collision. I project the new ball forward, when it hits a ball, I determine if it in front or behind, and adjust accordingly. I reorder the list, and tween the new ball into positions. I also move the front ball forward .5f. Since the ball were reordered, everything behind the new ball will travel backwards to its new position automatically.

    upload_2017-9-14_2-59-54.png
     
    Cromfeli likes this.
  28. armnotstrong

    armnotstrong

    Joined:
    Mar 3, 2017
    Posts:
    18
    Thanks for giving this diagram to clarify things, nice and neat :D

    So the main things remains that

    1. how the ball except the header ball know where it should be each frame? shall we pre-calculate each ball slot on the path? For, it seems the only thing the balls know is the distance (the diameter of the ball) from the ball it behinds. (lead ball position + (ball number * 1f)) is a one-dimension factor, but what the position calculating of the balls behind needed should be a two-dimension vector(if we build a 2d game)

    2. we should select a new leader ball when the previous leader ball was destroyed(by the same color eliminating), right?

    Here is the idea of pre-calculate the ball slot if I got you right



    only in this way I could understand how to make each ball knows where it should be in the frame update, or is there another way?

    Thanks
     
    Last edited: Sep 14, 2017
  29. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,000
    I have a ball controller that manages the balls along the path. In the update the lead ball is moved along the path. And then from that position, each subsequent ball is told what it's new target position is, using the path length and the PathGetPoint() method. Once all the target positions are calculated (including any removals/additions/changes) each ball has a method called advanceToTarget() which actually does the move and rotation and direction base on where the new point is. If that distance is over a certain threshold (say 2x the distance the previous moved), I use a smoothdamp to the position until is is under that threshold. (Speed adjusted for the size of the gap). Since the balls only care about their target location, the move forward or backward as needed.
     
  30. armnotstrong

    armnotstrong

    Joined:
    Mar 3, 2017
    Posts:
    18
    So the main idea is to get the position point of specific length/percentage of the whole path right?



    Do you do that by

    1) calculate the position each time each ball by calculating each waypoint distance and the margin distance between ball and waypoint.
    or 2) make a lookup table to find the position when needed?
    or 3) the waypoint system you use has utils to do that for you?

    In your response you mentioned a method PathGetPoint() can you give more details about this method if possible?
     
  31. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,000
    That functionality is built into DOTween.

    http://dotween.demigiant.com/documentation.php#gettingData

    PathGetPoint() returns a vector position on the path based on the percentage of the whole length. You just need to convert back and forth between the normalized position and the actual length/position.
     
  32. armnotstrong

    armnotstrong

    Joined:
    Mar 3, 2017
    Posts:
    18
  33. triangle154

    triangle154

    Joined:
    Mar 1, 2016
    Posts:
    3
    Hi @zombiegorilla , could you explain how to update the rotation of each ball, I'm building a zuma game based on your idea and i'm facing that issue. Any help would be appreciated.
     
  34. olynn_

    olynn_

    Joined:
    Feb 6, 2018
    Posts:
    4
    hi meher, my project is to make a game based on zuma. how do you code the ball to move along the path. pleas i need help. it is for my final year project :(
     
  35. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,182
    A path is usually just 2 points - a segment, and a point along that path is evaluated as a position between 0 and 1. You will need some maths.

    The simplest segment goes from A to B in a straight line:

    ball pos = Mathf.Lerp(a, b, t);

    t is a number between 0 and 1. therefore you only need to increment t for this particular ball. Another ball might start with a higher or lower t.

    For an entire curvy path, you will need to understand that this is just lots of 0 to 1 A to B points.
     
    olynn_ likes this.
  36. olynn_

    olynn_

    Joined:
    Feb 6, 2018
    Posts:
    4
    please notice me cuz i really need your help
     
  37. olynn_

    olynn_

    Joined:
    Feb 6, 2018
    Posts:
    4
    but im so noob in unity that i couldnt do anything that you said, i really need a tutorial from the beginning. anybody pleas help. T_______T
     
  38. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,182
    Don't see why I would teach you from scratch though. I have my own family, people I love, and so on in the queue for helping before I help you. So I gave a quick starter tip.

    My point being is, expect this to be fairly normal on a dev board. Where is the effort you even tried? How much spoon feeding do you require?
     
    zombiegorilla likes this.
  39. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,000
    I just rotate the ball based on the direction and speed. For simplicity, in my game, the balls are all 1unit in size, so it keeps the math clean and simple. The rotation and direction is done as a part of the move method, so it all just happens automatically.
     
  40. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,000
    https://unity3d.com/learn
    He explained it very clearly, but you are going to need to learn the basics to understand. A "tutorial" that covers the absolute basics and building a game isn't useful. Learn the core skills, and the rest will make sense.
     
  41. olynn_

    olynn_

    Joined:
    Feb 6, 2018
    Posts:
    4
    i tried to make the ball move. im following the way point path tutorial on youtube, i have problem to move the ball in a sequence, i had adjust the speed but it didnt work. somebody pls help me. what should i do?
     

    Attached Files:

  42. Crimx

    Crimx

    Joined:
    Mar 10, 2014
    Posts:
    3
    Hi, @zombiegorilla.
    Thanks to you, there's light for my Zuma-like game. For confirmation, how do you know where will each ball be in the next frame? Do you use specific speed, so the ball will be 0.5 percent from last frame, or do you use specific calculation so when you adjust the speed, the balls will be n percent ahead?
    I'm following your tips here, but still find some problem, like armnotstrong had (when inserting the shot ball to sequence, the position is awkward. Either there will be some gap or the ball merge with another). How you move the balls to make a gap when you use DOPath? I mean, afaik DOPath move with static speed (if you use speed based) or static travel time. So how you can perform that movement using DOPath?
     
  43. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,000
    I use an arbitrary speed value. Basically some value in distance to move each frame * the delta speed (moving forward of backward by how much -- a little bit if two balls just popped or a lot if 10 did or whatever, the time to close the gap * length of gap) * speed modifiers (level speed) * player modifiers(power-ups/abilities) * delta time. So basically Just distance.
    I don't move anything with DOPath. It is just for the path data/calculations.
     
    Crimx likes this.
  44. Crimx

    Crimx

    Joined:
    Mar 10, 2014
    Posts:
    3
    so, basically you just use DOPath only for creating the path and balls only following the path, not gameObject that has tween in it?

    Thank you for the reply, this make clear what's troubling me yesterday
     
  45. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,000
    Correct. Nothing is actually tweened along that path. (Well, not the balls, anyway). The balls all move at the same time in a ball manger class. There is path class that contains the dotween path. When a ball moves, it sends the path its current position on the path and it’s new position. (Floats representing progress along the length) and it returns two vectors, the position and rotation (the alignment direction). The ball it self handles the progress and target location, rolling rotation, timers, effects, etc. The ball manager keeps track of the front ball, index/stack of the other balls, and target locations.
     
  46. ipulCrimx

    ipulCrimx

    Joined:
    Aug 9, 2016
    Posts:
    3
    Thank you for explaining clearly. Now I can progress my project alot. My calculation about rotation is a bit different but it gives me same result :)
     
  47. ryeunmiguel12

    ryeunmiguel12

    Joined:
    Jun 3, 2019
    Posts:
    1
    Also, can you send me the code?
     
  48. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,000
    No.
     
    E5G, Vryken and Cromfeli like this.
unityunity