It so happened that for the past year I have been living in cold Finland. Initially, I came here to study, but for the past few months I have been actively looking for a job: I have been busy sending out my resume, have visited many events / conferences, visited several offices of various Finnish game-development offices. There are quite a few of them, by the way: good, the local International Game Developers Association (unlike native Ukrainian) lives, lives and gathers people for free beer once a month. So, I noticed that many companies (with a capacity of 10-20 people) are either switching, or have already moved to Unity3D.
Initially, the article was planned as a philosophical reflection on the balance of what_proger_writes / what_ player_vide, with admixtures of useful snippets / hints for working with Unity. In fact, during the execution of the test task in one of the companies,
a muse suddenly appeared to me to write a similar article, therefore I still do not know what will come of it.
For a start, a couple of
dozen words about myself: the 10th year has already gone, as I am interested in game-development - exactly 10 years ago I riveted the first game in Pascal, Sea Wars, aka sea battle. He was engaged at the amateur level, mainly in enthusiastic projects, a couple of times worked in relatively large companies, gained experience. He worked with many engines: first he worked with 3D Gamestudio, Ogre, Irrlicht, Leadwerks, and other Torque. I didn’t like Unity3D until this year. After
Global Game Jam - changed the view dramatically.
')
About studying: graduated from the Kiev Polytechnic Institute, he realized that the level of education leaves much to be desired (there were only 3 people in the group interested in programming), therefore he wanted it well and entered the Finnish university equally well.
In general, I will tell you about life in Finland, universities and the details of IGDA'vykh drinking bouts another time, it’s time to move on to game development.
The test task was as follows: it was necessary to write a prototype for the flight and landing of the aircraft, side view. Editing its position (transform) directly is forbidden, you can only use force (force) and torque (torque). I asked for time in 2 days, and finished the task after 2 days. True, I played with physics for a few more days, and after 4 days I sent the final version, which almost completely satisfied me.
So, this code criterion occurred to me:
1) a lot of code and time-consuming, for the player the effect is minimal
2) medium code, the effect is so-so
3) a couple of lines of code, the effect is obvious, the public is in shock
1. A lot of code, the effect is almost invisible / or it does not pay attentionThe most gemmorna and ungrateful part. Without it, no one will play the game, but even if it is done perfectly, no one will pay attention to this: it is in the order of things. But minor issues immediately struck. The short title is "
It must be present if it is not present - the file ".
Physics, for example, I reworked from scratch several times:
- at first I tried just formulas and real values ​​of mass / wingspan / engine power, however, later I still entered my coefficients. For myself, otmazalsya that important are not exact values, but the order of increase: for example, the dependence of lift on speed. As a result, the formulas have more of my "discoveries" than real formulas. Feil
- then I made a stern face, pumped up Sovkov books on aerodynamics, and began to do everything on science. However, the result was not much better: there were fewer additions, but the flight qualities were still unsatisfactory.
- it was useful to google similar flight simulators, it was played a bit with JSBSim. I did not find anything satisfactory, but I took note of the formulas.
- this time I scored on science and realism, put the aircraft minimum weight / span / power and began to combine all the new experience. On the last day, on the advice of an amateur IL-2, he added “pecking” with his nose, and on the whole it turned out very nice.
However, all this work, of course, is hardly noticeable when playing: it should be so, otherwise why bother to show a project at all? That, actually, is quite logical.
A piece of code from there (the whole function of calculating physics is quite large, I will give the most interesting part). I put more comments in this difficult place so that the reviewer could check out :)
I usually write for Unity on Sharpe, but asked to write in JavaScript. Well, JavaScript is so JavaScript ...
//// Thrust force // Ft = const * p * n^2 * d^4, // where const = 1,3; p = 0.125; n = power; d = screw diameter (2,4 for F4U-1 Corsair) // Ft = 5.39 * n^2 trustCoeff = rotorVelocity * power*power * powerCoeff; thrustVector = Vector3(1,0,0) * trustCoeff; //// Angle of attack, Lift force // http://wright.nasa.gov/airplane/lifteq.html // http://wright.nasa.gov/airplane/incline.html // C = 2 * m * alpha // L = 1/2 * p * V^2 * A * C , where p = 0.125 [kg * sec^2 / meter^4] at +15C; A = 9.172 for F4U-1 Corsair // L = 1.14 * V^2 * (m * alpha) speedWeight = 0.0125 * (velocityForwardVectorSqr/2); liftCoeff = wingspan * attackAlpha * speedWeight * weightCoeff; liftVector = Vector3(0,1,0) * liftCoeff; //// Air resistance = base resistance + inductive resistance // http://en.wikipedia.org/wiki/Parasitic_drag // http://en.wikipedia.org/wiki/Lift-induced_drag // resistBasic = Const * (p * V^2 * S) / 2 = Const' * V^2 * S // resistInductive = liftForce^2 / (p * V^2/2 * S) dragCoefficient = 2*airDrag + 2 * airDrag * horizonAngle * wingspanCoeff; dragVector = - airSpeedVector * dragCoefficient;
At the last moment I was also drawn by drawing. So you have an exclusive opportunity to enjoy my skills :)
Not hard to beat, I'm not an artist.
2. Medium code, so-so effectThe most average and nondescript part. The short title "
If there is - well, if not, well, okay ." Forces are spent on average ... hmm, and still gives a small flight for fantasy.
Muse hit the table with her fist, and told me to do it. I decided to show off a little and do a procedural generation of the landscape. In this case, it can be of 2 types: ocean or land. The land is realized in minecraft style, from cubes. I do not even know which piece of code to bring so that it was not very long, but interesting. I did, by the way, on the penultimate evening, looking at night, so there is much to refactor.
var firstIslandLength: int = Random.Range(70, 130); // width of island generationDist = 0; GenerateIsland(generationDist, firstIslandLength); var firstOceanLength: int = Random.Range(50, 100); generationDist += firstIslandLength + firstOceanLength; GenerateOcean(generationDist, firstOceanLength); var secondIslandLength: int = Random.Range(10, 30); generationDist += firstOceanLength + secondIslandLength; GenerateIsland(generationDist, secondIslandLength); var secondOceanLength: int = Random.Range(100, 150); generationDist += secondIslandLength + secondOceanLength; GenerateOcean(generationDist, secondOceanLength); var thirdIslandLength: int = Random.Range(70, 80); generationDist += secondOceanLength + thirdIslandLength; GenerateIsland(generationDist, secondOceanLength); GenerateTargetObj(generationDist, secondOceanLength); } function GenerateOcean(pos: int, length: int) { var newOcean = Instantiate(waterObject, Vector3(pos - 5, -2, 50), Quaternion.identity); newOcean.transform.localScale.x = length/4; Debug.Log("Ocean. Pos: " + pos + ". Length: " + length); }
The scheme will be something like this:
3. A couple of lines of code, the effect is obviousThe most important and interesting part of this opus, especially for those who take the first, second, third steps in game development and prototyping.
And for those who were waiting for hints on Unity3d . The short title "
If it is - cool, if it is not there - the project looks raw ."
In Unity:
- Import pack with skyboxes (Assets / Import package / skyboxes).
- Create a new object (Game Object / Create Empty), you can take an existing one.
- Create a new script SkyboxControl
- In the script write as many as 3 lines
var skyboxMaterials: Material[]; function Start () { RenderSettings.skybox = skyboxMaterials[Random.Range(0, skyboxMaterials.length - 1)]; }
- Drag the script to the newly created object, click on the arrow next to Skybox Materials, enter a number, for example 4: an array of 4 elements is created and opened
- Open Standard Assets / Skyboxes and fill in the above array with any skybox to choose from
What do we get? 1 minute was spent on actions (this, along with sipping beer and drying off), and a happy user each new restart of the game will observe a new random skybox.
Another example: sound. In my case, I had the sound of a rotating propeller, I wanted to demonstrate it beautifully.
You are welcome:
- We throw sound on the voiced object
- In the depths of the
Tundra, otters in the sockets of the script, somewhere in the Update () function we write as much as 1 line
soundPlayer.audio.pitch = rotorVelocity;
rotorVelocity is the player-controlled screw rotation speed, changing over the interval [0..1], depending on how long the user presses the button.
Everything, we receive profit. The greater the value of the speed of rotation of the motor, the faster the sound will be played. It's half a minute (along with beer drinking).
ConclusionDo not forget about such trifles. They are made fairly quickly (in particular, in Unity3d), and the project benefits bring a lot.
PS: yes, don’t believe it when they say on game dev competitions or on test tasks that the graphics are not important. Graphics is very important if the gameplay is not ingenious (which is extremely rare, but noticeable right away - hi Notch). In addition, it can be done very quickly, and the project will seem much more complete.
PPS: and one more thing: if
you're interested,
be sure to check out this presentation. No advertising: I see those guys for the first time in my life. But they say it.
PPPS: never got to that company. Therefore, I
post a link to what happened . I like the implementation, in principle, I will rework the physics one more time (or I will bring this up to standard), I will do a couple of dozen levels, but I will try to release it to some Unity portal of games.
Always open to constructive criticism.