当前位置:网站首页>How to realize the movement control of characters in horizontal game
How to realize the movement control of characters in horizontal game
2022-07-07 22:06:00 【51CTO】
hi ! Hello everyone , The ant is me . Welcome to my WeChat official account. 【 Little ants teach you to play games 】, Learn more original game development tutorials .
Today, let's share the movement control of characters in the horizontal version game , In a 2D In the horizontal version of the game , For the movement control of game characters , In fact, we only need to consider the horizontal direction . If the character can jump , You need to consider the movement in the vertical direction , This article only deals with character movement control in the horizontal direction .

Pictured , It's a persona , There are two things we need to consider .
The first point is to control the character to move horizontally , Press the button that moves to the right , His position should move to the right , When you press the move left button , His position should move to the left .
The second point is to control the orientation of the character , When moving to the right , The role should face right , When moving to the left , The role should face left .
Next , We come to wechat game making tools , Let's see how to realize such a mobile control function .
Let's first realize the utilization “ rocker ” Control the movement of the character .“ rocker ” The plug-in is located in the material library , Click on “ Explorer ” Medium “ Add material ” Button , Open the material library .

Select on the material library “ plug-in unit ”, find “ rocker ”, Add to the project .
next , Add another role for control , You can find it in the material library “ Jungle Adventure ” Medium “ Running characters ”( This material has running animation frames ), Add to the project .

Add after completion , Our project has become like this .

Next, we will use the joystick below to control the movement of the game character .
To realize the movement control of the spirit , In fact, tools have provided us with ready-made “ Behavior ” 了 , Choose “ Running characters ”, Then click... In the attribute area “ Management behavior ”, In the open behavior panel , Turn on “ Direction control ” Behavior .

After the behavior is turned on , Go back to the bottom of the attribute area to see about “ Direction control ” Some properties of behavior . Here, because we only need to control the horizontal movement , So choose the direction here “ about ” that will do .

besides , In the building block area “ Behavior ” In category , And “ Direction control ” Related building blocks .

Actually , In addition to “ rocker ” plug-in unit , Open the “ Direction control ” After the act , We have already completed the first step , Click to preview the scene , to glance at .

You can see , At this time, we can use the joystick to control the movement of the character .
Next , We continue to complete the second step , Is to adjust the orientation of the role , When moving the character to the right , Face right , When moving to the left , Face left .
To achieve this function , You need to know 2 Blocks , The first piece is “ Direction control ” Medium “ Direction of movement ” Building blocks .

Call this building block , We can get an angle value , By judging the current angle value , You can know where the current character is moving .

Pictured , If you are currently moving to the right , call “ Direction of movement ” Building blocks will get one 0 Value , Move left , Will get a 180 Value .
Next , Let's learn about the second building block . be located “ appearance ” Medium “ Turn your shape horizontally ”.

What this building block helps us solve is the orientation of the fairy image .

Pictured , The picture on the left passes “ level ” After flipping , It will become the right side .
After knowing these two necessary building blocks , Let's look at the implementation logic directly , Add the following building blocks to the character .

Here we are based on “ Whether to right ” The value of the variable for , as well as “ Direction of movement ” The numerical , To determine when to flip horizontally . If the current character faces right , Then only when the character moves to the left , It should be turned once , Let the character face left , vice versa .
Preview again , Look at the moving effect .

According to the control of the rocker , The character will move in the right direction , And will face in the right direction , In this way, the function of controlling character movement is completed ,
Someone might say , This is a 2D Horizontal game , There is no need to use an include 4 Rocker in two directions , Just use “ One left one right ” The two buttons of can control the direction . Using two buttons to control the direction is actually very simple .
We add two buttons to the scene , It means left and right keys .

then , newly build 2 Notifications , A notice “ Move to the left ”, A notice “ To the right ”.

The logic of these two buttons is very simple , When I press and hold the button , They send corresponding notifications to the characters in the game .


Last , Come to the role , Receive these two notifications , Then just call according to the notification “ Behavior ” Medium “ towards the left / Move right ” Building blocks are enough .

Last , Let's preview .

In this way, we can realize two mobile control methods , A kind of use “ rocker ” control , A kind of use “ Left and right buttons ” control , Actually “ rocker ” The plug-in just automatically handles the left to right movement for us .
Okay , Today's content is here , For the movement control skills of characters in horizontal version game , Have you got it ?
hi ! Hello everyone , The ant is me . Welcome to my WeChat official account. 【 Little ants teach you to play games 】, Learn more original game development tutorials .

边栏推荐
- The little money made by the program ape is a P!
- Reinforcement learning - learning notes 9 | multi step TD target
- Matplotlib drawing interface settings
- The function is really powerful!
- Lingyun going to sea | saihe & Huawei cloud: jointly help the sustainable development of cross-border e-commerce industry
- How to make agile digital transformation strategy for manufacturing enterprises
- Use json Stringify() to realize deep copy, be careful, there may be a huge hole
- ISO 26262 - considerations other than requirements based testing
- MIT6.S081-Lab9 FS [2021Fall]
- Navicat connect 2002 - can't connect to local MySQL server through socket '/var/lib/mysql/mysql Sock 'solve
猜你喜欢

Have you ever been confused? Once a test / development programmer, ignorant gadget C bird upgrade

PDF文档签名指南

L2: current situation, prospects and pain points of ZK Rollup

Open source OA development platform: contract management user manual

Matplotlib drawing interface settings

QT compile IOT management platform 39 alarm linkage

How to make agile digital transformation strategy for manufacturing enterprises
![Jerry's about TWS pairing mode configuration [chapter]](/img/fd/dd1e252617d30dd7147dbab25de5b4.png)
Jerry's about TWS pairing mode configuration [chapter]
Talk about relational database and serverless

Reinforcement learning - learning notes 9 | multi step TD target
随机推荐
大数据开源项目,一站式全自动化全生命周期运维管家ChengYing(承影)走向何方?
EasyCVR配置中心录像计划页面调整分辨率时的显示优化
Embedded development: how to choose the right RTOS for the project?
Why can't win11 display seconds? How to solve the problem that win11 time does not display seconds?
Devil daddy A0 English zero foundation self-improvement Road
Ad domain group policy management
强化学习-学习笔记9 | Multi-Step-TD-Target
The strongest installation of the twin tower model, Google is playing "antique" again?
Virtual machine network configuration in VMWare
Navicat connect 2002 - can't connect to local MySQL server through socket '/var/lib/mysql/mysql Sock 'solve
DBSync新增对MongoDB、ES的支持
L'enregistreur de disque dur NVR est connecté à easycvr par le Protocole GB 28181. Quelle est la raison pour laquelle l'information sur le canal de l'appareil n'est pas affichée?
Restore backup data on persistent volumes
Win11如何解禁键盘?Win11解禁键盘的方法
Win11时间怎么显示星期几?Win11怎么显示今天周几?
Take the intersection of two sets
Demon daddy C
[colmap] sparse reconstruction is converted to mvsnet format input
NVR hard disk video recorder is connected to easycvr through the national standard gb28181 protocol. What is the reason why the device channel information is not displayed?
An overview of the latest research progress of "efficient deep segmentation of labels" at Shanghai Jiaotong University, which comprehensively expounds the deep segmentation methods of unsupervised, ro