- Home /
2D Car game scene confusion
Hi, I am new bee in Unity 3d. I want to make 2D Car game. First I am trying with few test that am I able to make this racing game or not. The game concept is very simple car goes just straight and it if cross others car it get points and if hit then Game Over just like motor bike's game "highway rider". So I am confuse that Should I need to make whole long scene where my car travel one point to another or is this possible that I can create just few long scene and repeat it, I'll be happy if second option can achieve because this is easy for me to create graphics and if Yes then how can achieve my goal. Please help me and suggest me better way to do this. Thanks in advance.
Team_26 is definitely pointing you in the right direction, but it is a bad idea to loop gameplay by reloading the level. Ins$$anonymous$$d, just reset the car's position to the beginning of the track.
Also, you will need to leave some room at the beginning and end of the track so that the road looks continuous.
@spinnernicholas I 100% agree with you, it should be like this as you are suggesting, but what If, if I'll animate road and other car move backward and my(or current playing user) car will be in idle(or animate to looks like it traveling on road) so when other car(those are co$$anonymous$$g backward) hit my car then game over, what do you think its a good idea? and also how can I judge that my car pass the other car so that I can assign specific number to current playing user.
@spinnernicholas I am still confuse how to create scene in Unity3d for 2D car Game like to draw road and others, can you please suggest me any video tutorial to create 2D car game scene, $$anonymous$$indly don't suggest me any other scene videos, it'll be better that its related to 2D car game.
Answer by Spinnernicholas · Dec 24, 2013 at 04:51 PM
The main reason I would move the car and not the road, is that if you move the car, you are only moving one object, otherwise, you have to move everything except the car.
They have the same performance though, so it might be a better idea to to keep the car fixed. The best way to do this is create a gameobject that holds the road and all of the other objects(cars, environment,...) except the player car. I would probably still use a trigger to check when the car reaches the end of the road.
The 2D tools are really new and there are not really an good tutorials yet that I've seen.
First, set the main editor window to 2D mode. That will lock the camera to XY 2D mode. Then, create sprites from the menu bar at the top. Other than that, it's exactly the same as 3D.
Make sure and pay close attention to the hierarchy. That is the transform hierarchy of the scene. Each transform inherits the transform properties of it's parents.
Thanks @Spinnernicholas. Two things here which I need to know first there is flexibility on hold player car object and move other objects(with animated road) approach because I can create as many as I want opponent car and just reverse their position, ins$$anonymous$$d of first create scene and then repeat scene I think this will cause to show same scene again and again. Second thing is that after implementing your suggested approach just to move player car object and also move camera with it but what happening my car flicker and looks like that after some specific time car redrawing its self I don't know why this happen.? kindly check my below code which I wrote in FixedUpdate() function and suggested me better thing on this. Thanks again.
transform.position = new Vector3(transform.position.x,transform.position.y,Time.fixedDeltaTime *speed);
carCamera.transform.position = new Vector3(carCamera.transform.position.x,carCamera.transform.position.y,Time.fixedDeltaTime * speed-2);
where speed=2.0;
$$anonymous$$ake the camera a child of the car, then you don't have to manually move the camera every frame.
And I would probably use a velocity vector for elegance:
Vector3 velocity = new Vector3(0f,0f,speed);
transform.position += Time.fixedDeltaTime * velocity;
Thanks @Spinnernicholas, I am using Perspective Camera and I think the issue is which also mentioned in my other question's answer "If you are using a perspective camera, its likely that the road's center point becomes closer to the camera than the car's center point. Since the road is therefore "closer" than the car its drawn on top." In this Post "http://answers.unity3d.com/questions/602426/which-camera-projection-should-i-use-for-2d-game-i.html" I am pretty sure this is the problem, could you please guide me what should I do to tackle this issue.
Oh, yeah, that is an issue. I haven't messed with them, but you can use Sorting Layers to set the rendering order for sprites.
If you look at the Sprite Renderer, you can see sorting layer in it's properties.
You will need to read up on Layers and how they are used as sorting layers, but this is the way to go. It is exactly what Unity designed it for.
Answer by Team_26 · Dec 23, 2013 at 11:49 AM
You can create a street scene and when player is at the end of the street, load the level again. At first add a new object at the end of the scenea and remove "Mesh Renderer" component from this object. Now add a tag to this gameobject called END_GAMEOBJECT and make a simple script:
void OnTriggerEnter(Collider other)
{
if(other.gameobject.tag == END_GAMEOBJECT) { Application.LoadLevel("NAME_OF_YOUR_SCENE"); }
}
@Team_26 I am still confuse how to create scene in Unity3d for 2D car Game like to draw road and others, can you please suggest me any video tutorial to create 2D car game scene, $$anonymous$$indly don't suggest me any other scene videos, it'll be better that its related to 2D car game.
Answer by Team_26 · Dec 23, 2013 at 12:00 PM
It's possible that you can make a street in your scene and invisible gameobject at the end of this street. To make this object invisible, you must remove from it component called "Mesh Renderer". Now you must add to this gameobject tag called STREET_END (for example) and make a simple script:
void OnTriggerEnter(Collider other) { if(other.gameobject.tag == STREET_END) { Application.LoadLevel("NAME_OF_YOUR_SCENE"); } }