Full AIGC game creation, 2 hours to develop WeChat mini-games! (Complete ChatGPT training process)

Is it feasible to work for AI and develop a 3D game in 2 hours?

9f1a4500d2998f296c5002a38d205098.jpegSee 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.

464b8aab8b49eeb75faa72b44be2a643.png

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.

4390e0a10a1cb74ea0ca495b5e029eec.png

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!

c519af08b1fec8641dcad52a323eb055.png

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?)

9dbbc44b2b57b411f87051e70f086031.png

After communication, Xiao G quickly fixed the problem.

f9b6e59a6d3460d048dc7cf724007ba8.png

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?

3d9612d2003b06e0baa154025af0bd3c.png768715d4bc7ae25f6fb50d8309b9c4a3.png

So I started CPU small G, and for the next 5 function points, everything was fine.

e7faa2cc70cb27575bb4dbd9ca6391b2.pnga78ef804dda9fbc1b14453f008ad3971.png

The cooperation between Little G and me is getting better

538c289b61c55f319dc434fa08b543e2.png

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:

  1. Add logic to control snake movement using keyboard WASD.

  2. Fixed _moveDirection not having an initial value.

  3. Add the logic of snake body growth after eating fruit, and the fruit will appear randomly on the map.

  4. Fix the problem that this._snakeHead.position.subtract should not be used in the _checkCollision method.

  5. Add game boundary logic, the game will restart if the boundary is exceeded.

  6. Add a kun kun on the map, and the game will restart after encountering kun kun.

  7. After touching the fruit, Kun Kun's position will change randomly.

  8. 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.

  9. 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.

  10. The randomRange method is required.

  11. 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.

  12. Optimize the logic of generating special fruit, judge whether the previous node exists, and if it exists, reset the position instead of regenerating.

  13. Add four buttons, up, down, left, and right, and press the buttons to control the movement of the snake.

  14. Hide buttons when running on PC, show buttons when running on mobile.

  15. Use touch down to control buttons.

  16. Add a label scoreboard to show the length of the snake body, and the scoreboard will change every time it increases and decreases.

  17. Add a pause button, each click can toggle between pause and resume.

  18. Re-output the complete code, adding Chinese and English comments.

  19. Added a script for the camera to follow the snake's head.

  20. Modify the problem of obtaining the snake head node in the camera script.

  21. 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.

4f7697d68a0f1518bc379332af642939.png

Keep reminding little G

45e42f5b7244350a75dafee4b7975cca.png

quick fix

a4b728a67a5559d8280a2e4177cffaa1.png

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

2317184c5af63f62d91c53adc48d84c5.png

this information is too old

79ba0f31d6110685e0195e00fc145ec1.png

Repeated modification first solve VS

8f47f469c9004e263f1572664528f9c1.png

The FS part ignores the API first. This lighting model does not consider the viewing position of the camera.

2f623cb2ba9c65d19b0b7e78aa544595.png1b3c1e0d7f2f9c9eb8fb4b30dd2ab388.png

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

86d93c435503a40b13235262ee68f28a.png

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.

9feff4ce8303d0c33227d78961df4dd8.png

For the sake of face, Xiao G quickly went to Github to copy one.

fbe0e3ce5e672942c3dd4433afbf14eb.png

Something went wrong again when I ran! !

In fact, I don't blame Little G here, because the 2.x API is used.

ec87d7fd8da7f3c6a18c721e7c066e0d.png

We changed to add the effect before the perspective matrix transformation, and then we can see the effect of wind and grass.

b228fb361865d9127a3b60cc93f4d901.gif

Finally, set ok and enable instancing to ensure performance!

21891b9c4175fbbe90d3fa395571e47d.png

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

82928c07f470e3b92abbc87c324130dd.png

05 Skybox

AI Skybox: https://skybox.blockadelabs.com/

Also generated by prompts + blockadelabs, keywords Fantasy, Forest, Lake

826a678beaab15d1a7fcecd07159e977.png

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 -

98772a7d8567f5a3458c9c6699e50ddc.png

Icons

478bc21cc87080fcfa89f05852b1a656.png

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:

  1. 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;

  2. 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;

  3. If you find a problem, you need to provide as detailed feedback as possible, and AI will learn this problem;

  4. Try to communicate a large demand in one dialogue, and keep the context coherent;

  5. 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;

  6. 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.

df2e38b6b4c1a6c6aae5ad5412fb8722.png

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

Guess you like

Origin blog.csdn.net/6346289/article/details/129964867
Recommended