Parkur and Unity3d. Creation of your own Parkur system. Part 1
Good day. I think for those who do not know me yet. My name is Dima. I have been working c ++ developer for more than 5 years. I am currently working in a large Gamedev studio. In addition to work, I am fond of the creation of educational content for YouTube and Twitch channels.
In my small Petroject, I was inspired by the idea of implementing my Parkuru system.
What is parkour? Parkour – high -speed movement and overcoming obstacles using jumping elements. The main problem that needs to be solved: the character must be able not only to jump and run, but also interact with obstacles. The best example of Parku in games from the 3rd person is an Assassin’s Creed series, and in first-person games this is indisputably Mirror’s Edge. The last I will be inspired. I will analyze the decision that I have come to the moment and what tasks I solved at the same time.
Mark: This post is a little converted for the local format of my own article from the DTF website. On Stopgame there is no way to upload a program code in the readable form, so links to Pastebin.Com
What is an obstacle?
First of all, we will decide what we will perceive as an obstacle with which the player can interact. After short thoughts, I stopped at the parallelepippes, the rotation of which is around the axes Ox and OZ 0. That is, these are parallelepipeds of the lower and upper faces of which are strictly parallel to the surface of the “floor”. Do not perceive them as a set of abstract cubes by which the main character will climb. By setting their scale, from them you can make a platform from Mario, a flat advertising shield, pipes of the ventilation system, and so on.
What is our goal?
At the moment, I stopped at the simplest – noaccount-casinos.co.uk the character should instead of trying to jump on an obstacle, as in the games of the old school, try to climb on it, which will be accompanied by a special animation.
Missing obstacles into components
For each obstacle I identified 5 main elements: four walls and upper faces. Walls – This is the part that we will climb, Upper line – target. In order to break the obstacle, we will turn to the component BoxCollider. Using its size, as well as the scale of the object itself, its rotation and coordinates we calculate 8 points of parallelepiped angles in the global coordinate system. Let’s move on to the implementation of the method.
Implementation of breakdown of obstacles to walls
We will analyze the class Parkourobstacle. The main task of this class is to store wall set and upper line, as well as be able to determine which wall the point transferred to it. Consider the implementation, elements like properties and designers, I will exclude at this stage, so as not to distract from the essence. Full code will be provided at the end of the article.
Control
All preliminary operations are done. Now you can realize the character behavior. It is difficult to call this management, rather the definition of the moment when you need to run the parkour. I will not focus on my own implementation of the first -person management script. There are flaws in it and I don’t think that the next FPS controller can be surprised by someone. If you are interested in its implementation, write in the comments, I will write an article. I put all the logic of Parkuru into a separate script, I won’t say that it is easy and just suitable for any first -person management script. Nevertheless, with small changes in it and in your control logic, you can take it into service.
In a nutshell, the conditions for the launch of Parkura can be described as follows:
I think it is worth explaining only the first condition. Obstacles available for attempts will be determined by Capsulecollider, which will be a trigger collider. That is, it will only determine the hit and the exit from it of other colliders using functions OntrigGerenter And Ontriggerexit:
Further in the frame of the logic, having checked all these conditions and determining the obstacles to the park (Physics.RayCast From the position of the character, not the camera directed forward), we are convinced that the distance to the upper edge of the obstacle does not exceed the permissible limit (customizable parameter), and after that we start the climbing algorithm:
Cramping
The process of getting into an obstacle I divided into three stages:
Why do you need a transition? In most cases, the point of starting will not coincide with the position of the character in space, so you need to move the character smoothly and turn face to the wall. The speed of movement will be a customizable parameter. Next, an upward up and moving forward follows. This code will be executed within one Korutins.
Logic fits in three methods:
Startclimbing – calculating the starting points, shutdown of control of the launch of the calico, maintaining the speed of the character before the start of Parkuru
Conclusion
Our character learned to determine what is an obstacle, break it into the components of the elements and climb them. At the moment I am working on running mechanics on the walls. Thank you for your attention, write your wishes and questions in the comments. Follow the development of events, follow YouTube. Full development, detailed explanations and demonstration of work can be found in this video: