Is it feasible to work for AI and develop a 3D game in 2 hours?
See the end of the article for the source code download address!
Recently, technological development is changing with each passing day...
If Stable Diffusion and Mid Journey just killed art, we are still glad that R&D cannot be replaced.
Then GPT4, which came out in March, made me feel in crisis!
So many students said, at worst, I will be a UI cub , and let GPT4 write Shader for me? I am both skeptical and anxious about this.
This article starts from practice, from the program, Shader, art, to music, AIGC is responsible for the whole process as the UI cub, to explore the upper and lower limits of AI, and relieve anxiety.
written in front
An old habit, first do a mind map to determine what to do? The gameplay is the Snake that AI is familiar with, this time it will be upgraded to 3D Snake and new gameplay and complex terrain will be added.
Why write a mind map first, because there are many function points, and the changes in the middle are afraid of affecting the context of GPT4. At the same time, the functions will be disassembled as much as possible to avoid mutual interference.
01 Code function development
In the first communication, the API of GPT4 is still in Cocos 3.3 version. This time, it is developed using the latest version 3.7.2. Paste the first requirement first, and there is no error reported!
Then it crashes when it runs!
The initialization directly reported an error. I found that the direct null pointer reported an error. After checking, it was found that the direction vector of the _moveDirection snake was empty (guess why it can’t run?)
After communication, Xiao G quickly fixed the problem.
Everything works fine.
However, adding the logic of the fruit, the third time I ran it, I found that the direction of the snake was wrong. As an old UI cub, I quickly realized that the coordinates of the snake head were polluted. At this time, I have already started to retreat, and I will not be needed every time. Modify it?
So I started CPU small G, and for the next 5 function points, everything was fine.
The cooperation between Little G and me is getting better
It took about 50 minutes to write all the game logic and everything is normal.
02 The summary is as follows
During this conversation, we worked together to create a basic 3D Snake game. You raised some questions and requirements, and I made modifications and additions to the code. The following are your amendments and supplementary requests:
Add logic to control snake movement using keyboard WASD.
Fixed _moveDirection not having an initial value.
Add the logic of snake body growth after eating fruit, and the fruit will appear randomly on the map.
Fix the problem that this._snakeHead.position.subtract should not be used in the _checkCollision method.
Add game boundary logic, the game will restart if the boundary is exceeded.
Add a kun kun on the map, and the game will restart after encountering kun kun.
After touching the fruit, Kun Kun's position will change randomly.
After eating the fruit, there is a 30% chance to generate a large watermelon, and the length of the large watermelon will increase by 3.
After eating the fruit, there is a 10% chance to generate a Thunder Fruit. Eating the Thunder Fruit will increase the speed by 20% and increase the length by 2.
The randomRange method is required.
Added that a slow fruit will be randomly generated every 10-20s on the map, eating the slow fruit will slow down by 20% and reduce 1 section of body.
Optimize the logic of generating special fruit, judge whether the previous node exists, and if it exists, reset the position instead of regenerating.
Add four buttons, up, down, left, and right, and press the buttons to control the movement of the snake.
Hide buttons when running on PC, show buttons when running on mobile.
Use touch down to control buttons.
Add a label scoreboard to show the length of the snake body, and the scoreboard will change every time it increases and decreases.
Add a pause button, each click can toggle between pause and resume.
Re-output the complete code, adding Chinese and English comments.
Added a script for the camera to follow the snake's head.
Modify the problem of obtaining the snake head node in the camera script.
Added camera damping for smoother camera following.
Next comes the part of the more difficult terrain, and a new dialogue has been opened here.
Here, small G is needed to randomly generate plants on the terrain. It is no problem to run, but the generated position is obviously half of the position.
Keep reminding little G
quick fix
Then use this written method to communicate with the previous dialogue, and add logic to the snake head and object generation, and everything goes well!
The program part was completed without any risk.
03 Shader link
Next came the Shader, and my mind exploded for a while, because the 3.3 API is relatively old, so I started with the simplest Blinn-Phong.
I blew up halfway through the VS part
this information is too old
Repeated modification first solve VS
The FS part ignores the API first. This lighting model does not consider the viewing position of the camera.
Then various vector calculation issues, various API and Global variable issues
After 1 hour of tossing (the dialogue was changed twice in the middle, it was too tortuous, and I still recommend you to refer to it at present)... finally started running in 3.7.2
The next step is to write a wind blowing effect of grass, which is also a very common effect. Fortunately, I have made mental preparations. Here, the Chunk is missing when GPT4 comes up.
For the sake of face, Xiao G quickly went to Github to copy one.
Something went wrong again when I ran! !
In fact, I don't blame Little G here, because the 2.x API is used.
We changed to add the effect before the perspective matrix transformation, and then we can see the effect of wind and grass.
Finally, set ok and enable instancing to ensure performance!
04 music
https://mubert.com/
Music does not need AIGC to add scripts, directly use the AudioSource component of the engine, and use mubert for music
Keywords fun happy snake
05 Skybox
AI Skybox: https://skybox.blockadelabs.com/
Also generated by prompts + blockadelabs, keywords Fantasy, Forest, Lake
06 images
AI drawing: https://www.midjourney.com/
prompts:snake eating an apple, cyberpunk , in the space, hyper-realistic, surreal, fantasy, cinematic, extremly detail, 3D, manipulation, VFX, vivid background, cool --q 2 --v 5 -
Icons
write at the end
At present, the GPT database is relatively old, and there are many problems encountered in Shader. However, it is still very good to finish a small game in 2 hours.
The most important thing is that you don't need to use your brain much, the CPU AI output is fine.
Summarize:
Prompts need to be controlled at 2-3 each time, which is convenient for feedback and repair. For example, if you communicate all the requirements at once, if you report an error, it may be difficult for you and AI to locate;
The required content version information and language information should be clear. For example, the version is Cocos 3.3 (the latest version known to GTP4 2021), avoid using older APIs; the language requirement is TS (otherwise it may be copied to the JS version); Shader requires as much as possible Refer to Webgl, the syntax is Yaml;
If you find a problem, you need to provide as detailed feedback as possible, and AI will learn this problem;
Try to communicate a large demand in one dialogue, and keep the context coherent;
Adjust your mentality, AI is doing the work, you are the boss, coffee Youtube with a duck neck, found that there is a problem with the AI, the CPU is fine, if he can’t change it, continue to change it, it’s okay to watch him type;
Review, this is very important to let the AI output the review every time, and also observe whether the Prompts can be more streamlined this time, those communications are unnecessary.
For example, sometimes over-communication, AI will start to perform badly.
Adjust your mentality and have a better attitude (after adjusting your attitude, the comments are complete. At first, I thought it was because the Prompts were carefully added, but the result is not always true. OpenAI will judge whether it is malicious to AI. Excessive CPU may cause the conversation to terminate early).
Finally, the game experience link and source code download address, welcome to pay attention to the official account of the author!
H5 experience link:
http://learncocos.com/aigcsnake/
Source code download address:
https://store.cocos.com/app/detail/4775
Sun Ermiao public number:
Wonderful past
10 entrepreneurial secrets summarized by the father of ChatGPT "Sam Altman"!
ChatGPT and MidJourney have become my little secretaries! so cool
Facing the rise of AI, how should ordinary people make the right choice?
Spring is here, a different way of living can help you turn the tables against the wind!