top of page

Park Master Game Mechanics:

Welcome back. Hm, I have been playing this game called "Park Master" and i really loved it. So yes i sat down and replicated the basic mechanics which this game follows. As i always told, every casual/Mobile game revolves around a concept. Now lets decode that.


So here in this game, you have to create a path for your car and the car starts following that path. You have to take that car to the destination with out crashing it.

Lets start how?

Here i am gonna break down this logic into 2 parts:

Part 1: Create a path

Part 2: Make your car follow that path.

Cool right? I have attached a video, please watch that video(or play the game) to get full picture of what are we trying to achieve here!!


Great!! Lets do PART 1 - Creating a path for the car.

You have to move your finger/mouse on the screen to create the path.

This path i am gonna create that using "Line Renderer". Take an empty game object - in my case i named it "GameController" and attach line renderer component to it. Also attach a script(Line Controller) which will actually take care of this part of drawing a path.




I am attaching the screenshot of the script we attach to the GameController object.

Now the question is what are we gonna do in that script?

In this line renderer we pass points and this component draws line attaching those points. So all we have to do in the script is pass points to line renderer so that that component draws line attaching all those points - "Points" Vector is used for this purpose.

When ever you click the mouse button, A ray is casted from screen to the road block and we get point on the road using "Ray Cast" function. This happens every frame as we move the mouse and all those points are sent to line renderer component and we get a line on the screen.


else if(Input.GetButton("Fire1")) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); //Casting a Ray from camera screen to world RaycastHit hit; if(Physics.Raycast(ray,out hit)) { if (hit.transform.gameObject.layer == 8) { points.Add(hit.point); _lineRenderer.positionCount = points.Count; _lineRenderer.SetPositions(points.ToArray()); } } }




PART 2 - now the 2nd part is make the car follow the path we created.

For that we use "Nav Mesh". First thing to do here is bake the nav mesh. ( to bake the nav mesh make sure the block is "Navigation static") and add Nav Mesh agent to the car.

Now each point you have added to the line renderer becomes the destination point for the nav mesh agent(car). one it reaches the destination, set next point as the destination. This continues until it covers entire path(last point of the line renderer).



Drop a mail if you are facing any issues. I will be more than happy to help you :) Thanks/


FINAL RESULT:



 
 
 

Recent Posts

See All

Commenti


bottom of page