Search Unity

How to move a rigidbody object like Crossy Road?

Discussion in 'Scripting' started by Tipico, Aug 4, 2015.

  1. Tipico

    Tipico

    Joined:
    Aug 4, 2015
    Posts:
    25
    Hi,
    I'm making a kind of CrossyRoad game for android.

    I'd like to move a player with rigidbody for the reason of collision.
    I'm currently using rigidbody.velocity, but it turns not fixed amount movement.

    It moves 5 units forward once, then moves 3.33 units, then 8.43 ....so on.

    (What I want to achieve)
    Move the player 5 units away when I tap a screen once. I need the player to work with collision.

    I wonder if this is a problem with rigidbody.velocity or Input method is wrong.

    I'd really appreciate any help!

    Code (CSharp):
    1. private int leftRight;
    2. private int upDown;
    3.  
    4. void Update(){
    5.         leftRight =0;
    6.         upDown=0;
    7.  
    8. #if UNITY_STANDALONE|| UNITY_WEBPLAYER
    9.         leftRight = (int)(Input.GetAxisRaw("Horizontal"));
    10.         upDown = (int)(Input.GetAxisRaw("Vertical"));
    11.  
    12. #elif UNITY_IOS || UNITY_ANDROID || UNITY_WP8 || UNITY_IPHONE
    13.         if(Input.touchCount > 0){
    14.             //touch on screen
    15.             if(Input.GetTouch(0).phase == TouchPhase.Began){
    16.                 firstTouch = Input.GetTouch(0).position;
    17.             }
    18.  
    19.             // release touch/dragging
    20.             else if(Input.GetTouch(0).phase == TouchPhase.Ended && firstTouch.x>=0|| Input.GetTouch(0).phase == TouchPhase.Canceled){
    21.  
    22.                 Vector2 touchEnd = Input.GetTouch(0).position;
    23.                 x = touchEnd.x -firstTouch.x;
    24.                 y = touchEnd.y -firstTouch.y;
    25.                 firstTouch.x =-1;
    26.  
    27.                     //drag just too little / just a click
    28.                 if(Mathf.Abs(x) <swipeLength && Mathf.Abs(y) <swipeLength)
    29.                         upDown =1;
    30.  
    31.                     //drag left or right
    32.                 else if(Mathf.Abs(x) >=swipeLength || Mathf.Abs(y) >= swipeLength ){
    33.  
    34.                         if(Mathf.Abs(x)>Mathf.Abs(y))
    35.                             leftRight = x>0?1:-1;
    36.                         else
    37.                             upDown = y>0?1:-1;
    38.                 }
    39.                
    40.             }
    41.         }
    42. #endif
    43.     }
    44.  
    45.     void FixedUpdate(){
    46.  
    47.         if(leftRight !=0 || upDown !=0){
    48.             Move(leftRight,upDown);
    49.         }
    50.         else if(leftRight ==0 && upDown ==0 )
    51.             anim.SetBool("Idle",true);
    52.     }
    53.  
    54.     void Move(int leftRight,int upDown){
    55.         ridbody.velocity = new Vector3(leftRight,0,upDown)*200;
    56.  
    57.        
     
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,463
    I wouldn't bother with a ridgidbody body for movement. Maybe for collision detection. I would just move the position forward a set amount and animate the transition.
     
    dogzerx2, Schneider21 and Master-Frog like this.
  3. Master-Frog

    Master-Frog

    Joined:
    Jun 22, 2015
    Posts:
    2,297
    The vertical motion doesn't have to be part of physics. You could parent that chicken to a cube and slide the cube around. Just make the chicken jump with an animation. Remember it just has to look right to a player, however you get there all up to you.

    I don't use physics for most things because it has an element of randomness... but keep that in mind, you may need that randomness one day.

    Anyway, I have always created a per update or per step Movement variable that gets added to the position per each update, all you do is simulate a slowdown by bringing that movement amount to zero slowly over time. You can also set how fast it slows down with another variable, like friction. Why this is good... well it always seems to work perfectly. Never failed me.

    Almost forgot make sure you multiply that motion by Time.deltaTime so it works on different frame rates.

    Good luck
     
    Last edited: Aug 5, 2015
    Schneider21 likes this.
  4. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    IIRC Crossy Road is a grid(?) They probably don't use physics.
     
    Kiwasi likes this.
  5. Master-Frog

    Master-Frog

    Joined:
    Jun 22, 2015
    Posts:
    2,297
    True! You could lerp that position.
     
  6. landon912

    landon912

    Joined:
    Nov 8, 2011
    Posts:
    1,572
    You could just use root motion in an animation the moves a constant distance.
     
  7. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,463
    I've got an interview with Matt Hall and Andy Sum for a job tomorrow. I could always ask them how they did it.
     
    TylerPerry likes this.
  8. minionnz

    minionnz

    Joined:
    Jan 29, 2013
    Posts:
    391
    Good luck! Let us know how it goes
     
    Kiwasi likes this.
  9. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    Good luck!
     
    Kiwasi likes this.
  10. Tipico

    Tipico

    Joined:
    Aug 4, 2015
    Posts:
    25
    So, are you saying that you would use transform.translate then attach ridgidbody for collision?
    I did it before, but the collision's detection messed up with transform.tranlate or other non-physics movement.
    Did I miss something??
     
  11. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,463
    If moving the transform directly is giving you collision detection issues try using Rigidbody.Move.
     
  12. Tipico

    Tipico

    Joined:
    Aug 4, 2015
    Posts:
    25
    Thank you for good explanation!
    Yeah...I don't need physics either.
    I use rigidbody only for the collision sake. I messed with it when I used transform.translate/transform.position etc.

    I'm trying to understand your method well.
    I don't know if I get it right though...

    How do you detect collision by this?Raycast?
    I want my player to bang trees and enemies( well, I have enemies instead of trains).
     
  13. Master-Frog

    Master-Frog

    Joined:
    Jun 22, 2015
    Posts:
    2,297
    Just fyi modifying the transform directly bypasses physics for a moment, then the physics try to catch up and objects push away from each other as if they had hit each other harder than they did. You have to move the rigidbody using physics if you want it to work right.
     
  14. Tipico

    Tipico

    Joined:
    Aug 4, 2015
    Posts:
    25
    Yeah....I don't mean to use physics , but I need collision.
    How do you not mess with collision without rigidbody?
     
  15. Master-Frog

    Master-Frog

    Joined:
    Jun 22, 2015
    Posts:
    2,297
    What I would do is make it so the object moves exactly the right amount per swipe. You can raycast out one jump distance to see if something is there. If not, jump. Only do this for the environment. The actual animation part is not important for moving in the environment and interacting with walls. So, it is arbitrary as far as moving the chicken. You can use Lerp to move him between last position and next position. Disable swipes until current position = next position. Cars and other things can be handled without physics as well. Use triggers. When he hits a car, arrest his motion and parent him to the car. On and on, no need for physics.

    Physics is expensive and for use when you need to simulate physics. Crowd simulation, is a big one. Sports games. Just think of physics as being there for when you need realism.

    You can make cross road easily without the physics engine.

    Also, I would make it so he falls if there is no ground below him via raycasting, this way you can easily implement ditches and water. All you have to do is tag the logs as ground.

    Also, for the ground, raycast from all four corners, there may be a boxcast or sweeptest method but I never needed it so I never used it. Figures.

    Physics can really mess up a simple game, you need to be pretty good to use physics without "weird stuff" happening.

    Night, good luck.
     
    Last edited: Aug 5, 2015
  16. Tipico

    Tipico

    Joined:
    Aug 4, 2015
    Posts:
    25
    Wow!!!! I'm counting on you!! Good luck :D

    Actually I succeed to move the player by same amounts per an input( tap) last night.
    What I did is just move the method of Update to FixedUpdate.
    I wonder if my input will slow down by this solution.
     
  17. Tipico

    Tipico

    Joined:
    Aug 4, 2015
    Posts:
    25
    I'm a little bit confused here:(
    English is my second language, and I'm a beginner in programming.
    Please be patient with me if I say something idiot!

    Do I understand you correctly?

    1)No physics needed in this game.
    2)Move the player position directly by Lerp.
    3)Detect obstacles via Raycasting.
    4)Use trigger to detect if enemies hit.

    I still need a rigidbody to deal with trigger right?
    So, I should set all rigidbody as kinematic, then move their transform directly.

    What do you mean by this?
    I thought you were saying that I don't need to move rigidbody but transform.position with Lerp.


    I will try your method!
    Thank you for helping me;)
     
  18. minionnz

    minionnz

    Joined:
    Jan 29, 2013
    Posts:
    391
    There are two ways of doing it:
    1 - using Rigidbodies and physics. You can't move transform.position because it can mess with the physics. You'll need to use Rigidbody.MovePosition instead.
    2 - Not using Rigidbodies or physics at all - just Colliders. Here you would move transform.position, but you'd use Raycast to detect if there are any other colliders in your path before you move.

    I'd personally go for option 2. Example of using Raycast: http://www.theappguruz.com/blog/collision-detection-without-rigid-body-in-unity
     
  19. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,569
    If you keep everything to 1 grid then you can move exact by using vector3.forward etc. I used that for a snake game to move the segments then put a time delay in between each movement so it slowed down enough to look smooth.
     
  20. Master-Frog

    Master-Frog

    Joined:
    Jun 22, 2015
    Posts:
    2,297
    Yes, for two objects to register Trigger events, both need Colliders, at least one of the two must have a Rigidbody and at least one of the two must have their Collider set to IsTrigger. Yes, IsKinematic is what you want.

    I was just telling you why non-kinematic Rigidbodies don't like it when you set their transform directly, since you had encountered it but I figured you might want to know why as well.
     
  21. Tipico

    Tipico

    Joined:
    Aug 4, 2015
    Posts:
    25
    Hi,
    Thank you for explaining me a lot !
    I really appreciate it :)

    I tried your method!

    1)No physics needed in this game. // Yes, I set my player to Kinematic.
    2)Move the player position directly by Lerp. //Yes, it works perfectly.
    3)Detect obstacles via Raycasting. // Ummm it works not well ??????
    4)Use trigger to detect if enemies hit.// Yes, all onTriggerEnter works perfectly.

    My problem is that banging to obstacles via Raycast. ----3)
    I wrote a script to stop the player move if ray hits obstacle's layers.
    The player stops mostly, but sometime go through the obstacles.
    I wonder if that problem is the same with bullet's problem which known as that raycast doesn't work with high speed objects.

    I googled a lot about non-physics games, but official unity tutorials always use rigidbody to move...
    Do you know any nice tutorials for non-physics games?
     
  22. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,463
    I wouldn't bother with raycasts to detect obstacles. Build a simple array with the obstacles position built in.
     
  23. Tipico

    Tipico

    Joined:
    Aug 4, 2015
    Posts:
    25
    Thank you for the answer!
    I was seeking the way of moving rigidbody because of the collision matter.
    But you made the snake game without moving rigidbody.
    Did you use raycast to detect obstacles?
    I guess your snake won't bang walls to try sneak out of a dungeon, will it?
    My player sometime go throw obstacles by raycast's failure :((
     
  24. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,569
    Everything was also sized as 1,1,x but that meant running alongside them also triggered collisions. Because I was moving everything 1-grid I just shrunk the colliders to 0.75, this was because the snake segments were teleporting 1 grid so would therefore collide when they were instantiated inside the object. From the player perspective they never knew it was inside the object as it happened so fast they just assumed that they'd touched it & therefore died. The snake could go thru the boundary walls & was teleported to the opposite side of the board while maintaining their movement direction. This made it look like they had moved off one side of the play area & entered in the other side.

    I have only ever used ray cast once & haven't learnt how to do them properly so I just use normal colliders & triggers. My games are so tiny (& unpublished) that I don't need to optimise for collisions yet.
     
  25. Master-Frog

    Master-Frog

    Joined:
    Jun 22, 2015
    Posts:
    2,297
    It takes some practice to figure it all out, that's all
     
  26. Tipico

    Tipico

    Joined:
    Aug 4, 2015
    Posts:
    25
    Thank you for the suggestion !
    Build an array with the obstacles position?
    Does that mean something like this?
    Code (CSharp):
    1. public Trasnform[] obstacles;
    2.  
    3. void Update(){
    4. if(transform.position == obstacles)
    5.   //stop the player
    6.  
    7. else
    8.   Move();
    9. }
    10.  
    11. void Move(){
    12. //move the player
    13. }
    My obstacles are randomly built.
    Do you think I still can do the method of yours ?

    I'm getting to think of going back to move rigidbody for collider..since Raycast doesn't work like what I expected.

    How was the interview?? I believe it went well:)
    Any tips from them ? I'm looking forward it ;)
     
  27. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,569
    If you did a list you could add the objects to the list when they spawn but I'm not sure where you'd go after that. For my snake game I had a list of spawn points that I looped through to find vacant positions when randomly generating the obstacles but I did all the collisions with the collides as above.
     
  28. Tipico

    Tipico

    Joined:
    Aug 4, 2015
    Posts:
    25
    Oh,I see, I understand your way now!
    You detect collision with OnTrigger,then if it touch a collision that inside a wall, your snake dies.
    I will try that now :)
    I almost try Coroutine just now.
     
  29. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,463
    Not really, I mean something much simpler. An array of ints (or enum if you prefer). In Crossy Road you could use a 0 to indicate a grass, 1 to indicate a road, 2 for water, 3 for an obstacle and so forth. Collision checking would simply be a case of checking the grid position the player wants to move to and seeing if its passable. If you wanted the same flexibility of Crossy Road you could flesh it out a bit more by using a struct or class with some more detail. Perhaps including the type of obstacle, and indications about pass ability and so forth.

    Dynamic obstacles could also be handled the same way, simply writing their positions into a 2D array each frame.

    Crossy road has no need for rigidbodies or physics or triggers or raycasting. The core game mechanic is blindingly simple. That's why it was one of the first games built, the original dates back to 1981. Hipster Whale hit on something brilliant when they remade the game for mobile devices, and their art and implementation is pretty good. But the core gameplay wouldn't have taken more then a day or two.

    In this game the visualisation sits on a separate layer to the game model. It would simply be a case of checking the 2D array and figuring out what should be rendered at each position. This would be the first point your code actually cared about transforms.

    The interview went well. It was just first round with their HR firm. If they like me technical interviews will be next week. My main concern will be salary, it looks like going into games full time will be a significant pay cut. Its a big risk I'll have to discuss with my wife. Historically we've chosen security.
     
  30. Tipico

    Tipico

    Joined:
    Aug 4, 2015
    Posts:
    25
    Thank you Thank you Thank you !!!!
    I feel that I've been blind for long !
    I didn't know the original of Crossy Road, so I've never look into it :O
    I guess Crossy Road needs rigidbodies and triggers for getting coins, doesn't it?
    I have coins too, so I'm not yet sure if I can remove all rigidbodies.

    This is a big step I'd never think of if I was alone!
    I'm glad that I posted my question here... everyone are so kind to give me new ideas.

    Anyway, I will write my result later !

    What:eek:!? Is that so?
    I googled about game programmers’ salary (sorry:p), it said that unexperienced programmers make an average salary of $72,000 in US !! I envy you a lot!
    My goal is that to make a lot of small games to make some pennies while I'm with my baby in home in future ;)
     
  31. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,463
    Everything is represented in your 2D array (ie the grid the game is played on). Checking for collision is as simple as checking what other objects are at an array location. No need for ray casting or triggers or rigid bodies or any of that.

    The figure seems high to me. But I don't work in the industry, so I have no idea. I'll wait till I have an offer on the table before making any judgement calls.

    But the general feel I've got from google is that noob game devs make less then experienced chemical engineers. On the other hand game dev does seem to offer some attractive life styles.
     
  32. Frpmta

    Frpmta

    Joined:
    Nov 30, 2013
    Posts:
    461
    Except it is hard in the modern landscape for a chemical engineer to land a job :D

    That link is interesting.
    I tried to make an object(fired arrow) glue to another object(target) without a Rigidbody and then start moving with that target object.
    But I didn't make use of Colliders thinking they were an instant way of making things depend/rely on physics.
    So are colliders independent from the Physics engine and their position updates at the same rate as Update and not FixedUpdate(Physics Update)?
    Does that mean if I make an object fall down at 10000units per second, and there's a collider in the way and I have it set up to stop if the raycast finds a collider, it won't miss the collision no matter the speed?
    (Why ask If I am going to try it right now :D)
     
  33. minionnz

    minionnz

    Joined:
    Jan 29, 2013
    Posts:
    391
    Oh I'm not sure actually. The "no physics at all" part was incorrect. I'm sure that the colliders still rely on physx - but I don't know if you need to use FixedUpdate or if that is only for Rigidbodies.

    If you're falling at that speed, then you'll want to raycast 10,000 units ahead before moving the object - yes, it should detect the collider.
    Keep in mind that I haven't tested anything of this, so may be wrong. It's been 6+ months since I last used Unity.
     
  34. Tipico

    Tipico

    Joined:
    Aug 4, 2015
    Posts:
    25
    Arrrgh:confused:!
    I can't figure it out by myself!
    Is that really simple?
    I'm studying "2D array" things for these few days...I didn't know that thing exist until you mentioned.
    Youtube explained me how to make a 2D array map(?), but not how to use it as a detector.

    I believe this is what you meant.
    https://msdn.microsoft.com/en-us/library/2yd9wwz4.aspx

    I don't know how to use this for game.
    I guess I should have use this array for making environment, then find a position?
    But, even the official tutorial ''Roguelike'' use raycast to avoid obstacles...


    What is the benefit to use 2D array for collision?
    Is that cheapest way to do that?
    Collide with rigidbody > raycast / on Trigger > 2D array ???

    Correct me if I'm wrong:oops:
     
  35. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,463
    Using a 2D array will have performance benefits. It's also unambiguous as to the position of each object. You don't have to do it this way by any means.

    Most games use the physics engine, because most games need continuous positioning and collision detection. Crossy roads is somewhat unique in today's environment in that it uses grid based movement. (That said there was a time when every game used grid based movement.)

    Try drawing the grid structure on paper to see what it looks like. That may help.
     
  36. Tipico

    Tipico

    Joined:
    Aug 4, 2015
    Posts:
    25
    I did drawing the grid on the CrossyRoad.
    But..umm..not clear to me:(
    I thought I could find the Frogger's script somewhere, but I haven't found it yet.

    I'd really like to know this new method even though I could just use OnTrigger or raycast.
    It's always better to have choices ;)

    I wonder, do yo think "pathfinding" is what you are talking about?
    I haven't use/study it yet, but it looks similar to me.
    If that's so, I'll focus on pathfinding's tutorials.
     

    Attached Files:

  37. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,569
  38. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    An array like this:

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class MapCollision : MonoBehaviour {
    6.     byte[,] collision = new byte[,]
    7.     {
    8.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
    9.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
    10.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
    11.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
    12.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
    13.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
    14.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
    15.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
    16.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
    17.         {1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,},
    18.         {1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,},//These could be trees or something.
    19.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
    20.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
    21.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
    22.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
    23.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
    24.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
    25.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
    26.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
    27.         {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,},
    28.     };
    29.  
    30.     int x;
    31.     int y;
    32.  
    33.  
    34.     void Update ()
    35.     {
    36.         //Just move it forward!
    37.         transform.position += new Vector3(0f, 0f, 10f * Time.deltaTime);
    38.  
    39.         x = Mathf.RoundToInt(transform.position.x);
    40.         y = Mathf.RoundToInt(transform.position.z);
    41.  
    42.         //Remember they are backwards.
    43.         if (collision [y, x] == 1)
    44.         {
    45.             Debug.Log("Dead");
    46.             gameObject.SetActive(false);
    47.         }
    48.     }
    49. }
    I just remembered one of the developers saying they used a grid, might not be worth doing but it's super fast.

    This script doesn't work well, it's just an example of how this type of stuff can work.
     
    Tipico and Kiwasi like this.
  39. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,463
    That kind of the frame work I had in mind. If you wanted to get fancy you could use an image format to define the levels to, images are great for 2D data. I do believe crossy road is procedurally generated, so images may not be all that useful.

    I would consider doing move code the other way around, store the position of the character in a couple of ints that you increment, and set transform.position based on those ints. But either way will work.
     
    TylerPerry likes this.
  40. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,463
    Crossy Road did another brilliant simplification on pathfinding. One of the issues with infinite runners is ensuring there is always a valid path through the maze. Crossy road solves this by making the central tile always passable. Thus there is never a path that dead ends across the board.

    The moving cars and logs hide this somewhat, but its there.
     
    Tipico likes this.
  41. Tipico

    Tipico

    Joined:
    Aug 4, 2015
    Posts:
    25
  42. Tipico

    Tipico

    Joined:
    Aug 4, 2015
    Posts:
    25
    Thank you! Thank you so much!
    It helps me to start cording !
    But, I'm having trouble finding tutorials of generating floor tiles while a player moving.
    How can I approach this ?
    I googled about 'pathfinding', 'tilemaps' and '2D array', but they are mostly about board games , or one screen games.
    One screen games means like the Frogger, It's not like Crossy road.
     
  43. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,569
    Wouldn't you just have something that says if the player moves towards the top edge of the screen the. Destroy the first row & instantiate a new row at the end of the array?

    Probably best to get it working on a fixed board style game first & once it is all working then move onto the endless screen version.
     
  44. Tipico

    Tipico

    Joined:
    Aug 4, 2015
    Posts:
    25
    There is?! I didn't know that...I always die after few steps:rolleyes:
    My problem of infinite runners is generating the infinite floor..I can't find this on Google yet.
    Do you know what keyword fits with this method you use?
    "2D array" keyword told me just how to make a static 2d array map.
     
  45. Tipico

    Tipico

    Joined:
    Aug 4, 2015
    Posts:
    25
    Yes,Yes, I have those kind of method already, I just don't know how to apply to 2D array:oops:
    My game was almost reach the goal until I found my player is not moving properly on Phone.
    I guess I will use other method for this game for now as I want finish this game up.
    I'd make a new game with 2D array for a board game next time ....maybe...
     
  46. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,463
    More smoke and mirrors. In a typical infinite runner the player never moved. The ground simply is moved underneath them.

    Once the ground is off screen it's moved back up to the top of the screen and reused. Think of a treadmill.

    You can destroy and recreate the scene instead of moving it. But expect performance issues, it plays havoc on your memory management.
     
    Tipico likes this.
  47. Tipico

    Tipico

    Joined:
    Aug 4, 2015
    Posts:
    25
    I see! That's really simple !
    Thank you for a lot of infomation!
    I have a lot of questions about 2d array, but since my first question isn't about 2d array, I don't know if I should continue it here... so I post new specific question about 2Darray in the following link.
    http://answers.unity3d.com/questions/1033759/grid-based-game-using-2d-array.html

    I'd appreciate if you could check the link when you have a time:)