Tag: Star Unity will be associated with the date for color instance OID
ARPG: Action-oriented role-playing games
Most of the ARPG games use joystick operation to follow the protagonist in a third-person camera, in fact the character only walks eight directions, upper, lower, left, right, left, left, right, right, top
The idea of controlling character movement
1: In the Arpg game, the protagonist characters under the joystick control walk;
2: Characters encounter Obstacles (collider) will not cross the past;
3: Joystick control leading characters in 8 directions of walking;
4: Using the Charactercontroller role Controller component: It allows you to move easily without having to deal with rigid bodies in situations where you are subject to collisions, without actually having physical properties of the rigid bodies. The role controller is not affected by force and only moves when you call the Move function. It performs movement, but is subject to other collider.
It used to be on the character Mount rigid body (with the inside of gravity) and collider components, if encountered other rigid body will also be affected by some bad effect, with the Charactercontroller will not have this irrelevant physical force of the influence.
5: Move the role by calling the role controller's move function;
6: Rotate the character animation according to the direction of the joystick;
Charactercontroller components
1: Properties Panel Properties:
Slope Limit: A role collider can only climb a ramp that is lower than the specified angle: (in degree)
Step offset: Up stairs mode, less than step offset steps, you can go straight up;
Skin Width: Two collider can penetrate into each other deep into the skin, generally set to radius of 10%;
Min Move Distance: Call the Move function moves the minimum movement, if the moving distance is smaller than this, will not move;
Center: Relative to the position of the transform role called Capsule Body Center;
Height: high capsule body;
Radius: The radius of the capsule body;
2: Collision Detection:
void Oncontrollercolliderhit (Controllercolliderhit hit) {}, as with a typical collider. This interface is called when there is a collision. It is only called when collisions with other objects with Charactercontroller components occur.
3: Important Method:
Move (VEC3 offset): the distance to move;
If a role is mounted on the Charactercontroller component. In order to control the movement of the character, you don't have to change the position of the character node, just move the component and the character will follow.
I interpret this component as a capsule collider component that can affect the node and can set special moving properties capsule Collider
The basic idea and principle of the remote pole writing
1: Take 8 directions For example, the whole circle is divided into lower, right, right, top, top, left, left and bottom left;
2: When our remote sensing center point is in the range of a certain direction, then it belongs to this direction;
3. Exclude an invalid joystick area in which the protagonist will not move along
4. The distance of the character movement is a scalar, equal to the speed multiplied by the time, and the character moves the whole behavior is a vector, so also to consider the direction, get the angle of the rocker to know the direction of the movement and the role to the final destination of the scalar distance decomposition into the X and Z axis direction of the distance.
Calculates the coefficient of decomposition of the vector corresponding to the current distance according to the direction of the stick
Instance
1. Create Unity project and file directory
2. Import people model resources and map resources, and stick packs (79)
3. Character model material ball shader use mobile diffuse to correlate maps, set model---->RIG---->animation Type---->legacy---->apply
4. Add running animations to the animation of the character model, 136-161 frames are running frames, Wrap Mode---->loop---->apply, the characters are configured and dragged into the scene
5. Create a planar plane, relate material, enlarge 10 times times
6. No need to add collider, as long as the protagonist to add Charactercontroller components, adjust the capsule body of the component to completely cover the protagonist, it has a collision area but not the impact of force.
7. Add joystick, Hedgehog Team---->easy Touch---->add Easy touch for C#,hedgehog team---->easy Touch----> Extension---->adding a new joystick
8. Adjust the camera position to the best position where the protagonist movement can be seen
9. Under the main character, mount a script person to control the character movement through the joystick.
Person.cs
usingSystem.Collections;usingSystem.Collections.Generic;usingUnityengine;enumDIR//define an enumeration to differentiate between eight directions of a character move{Invalid_dir= -1, up=0, down=1, Left=2, Right=3, RU=4, LU=5, LD=6, RD=7,} Public classperson:monobehaviour{floatMove_speed =8.0f;//character Move SpeedCharactercontroller C_ctrl;//Role Controller Components PublicEasyjoystick Joystick;//rocker Lever float[] x_set;//decomposition factor on X-axis in eight directions float[] z_set;//decomposition factor on z-axis in eight directions float[] rot_set;//angle table for the orientation of the character faceVector3 Camera_offset; //Use this for initialization voidStart () { This. C_ctrl = This. Getcomponent<charactercontroller>(); //follow up, down, left, right, right, upper left, bottom left, bottom right, order configuration This. X_set =New float[8] {0,0, -1,1,0.707f, -0.707f, -0.707f,0.707f};//cos45=0.707,sin45=0.707 This. Z_set =New float[8] {1, -1,0,0,0.707f,0.707f, -0.707f, -0.707f }; This. Rot_set =New float[8] {0, the, - -, -, $, - $, -135,135 }; This. Camera_offset = Camera.main.transform.position- This. transform.position;//get the three-dimensional distance of the current camera and character } intGet_dir (floatr) {if(R >=-mathf.pi && R <-7* Mathf.pi/8) { //part of the left return(int) DIR. Left; } Else if(R >=-7* Mathf.pi/8&& R <-5* Mathf.pi/8) {//Lower left return(int) DIR. LD; } Else if(R >=-5* Mathf.pi/8&& R <-3* Mathf.pi/8) {//under return(int) DIR. Down; } Else if(R >=-3* Mathf.pi/8&& R <-1* Mathf.pi/8) {//Lower Right return(int) DIR. RD; } Else if(R >=-1* Mathf.pi/8&& R <1* Mathf.pi/8) {//Right return(int) DIR. right; } Else if(R >=1* Mathf.pi/8&& R <3* Mathf.pi/8) {//Top Right return(int) dir.ru; } Else if(R >=3* Mathf.pi/8&& R <5* Mathf.pi/8) {//on return(int) DIR. up; } Else if(R >=5* Mathf.pi/8&& R <7* Mathf.pi/8) {//Upper left return(int) DIR. LU; } Else if(R >=7* Mathf.pi/8&& R <8* Mathf.pi/8) {//the other part of the left return(int) DIR. Left; } return(int) DIR. Invalid_dir;//Invalid zone } voidwalk_update () {floatx = This. Joystick. joysticktouch.x;//x-coordinate of the joystick coordinate system floaty = This. Joystick. JOYSTICKTOUCH.Y;//the y-coordinate of the joystick coordinate system floatLen = (x * x + y * y);//do not open the root is because the cost is too large, and in the update, every frame open root can not stand if(Len < (0.5f*0.5f))//The joystick moved to this area is not valid { return; } //get this direction floatR = mathf.atan2 (y, x);//using inverse trigonometric function, get the angle of the vector, [-pi, PI] intDIR = This. Get_dir (R); if(Dir! = (int) DIR. Invalid_dir) {floats = This. move_speed * TIME.DELTATIME;//the distance to move every secondVector3 offset =NewVector3 (S * This. X_set[dir],0, S * This. Z_set[dir]);//break this distance into the X and Z directions. This. C_ctrl. Move (offset);//each frame is moved//switch the direction of a character's walkVector3 E_rot = This. Transform.eulerangles; E_rot.y= This. Rot_set[dir]; This. Transform.eulerangles =E_rot; //End } //End } //Update is called once per frame voidUpdate () { This. Walk_update (); Camera.main.transform.position= This. Transform.position + This. Camera_offset;//keep the distance between the character and the camera unchanged }}
10. Operation Effect
About unity in ARPG game character movement