This article provides a common way to create a map of the 2.5D game, which realizes the analysis of Google and individuals. If there is something wrong, please also point out in time.
Below will leave a screenshot of the supporting projects in this article, and we will start our text.
2.5D games between 2D games and 3D games are a special way to present. Common implementation ideas are divided into two types:
-
One is the use of 3D scenes and assets, but players can only move on the two fixed axes. The masterpieces are: LOL, Super Mario 2, etc.
“Super Mario 2” -
The second type is to use 2D assets and knowledge to achieve the corresponding effects with the visual effects of the third dimension. The masterpiece is famine, The Wild and Heart
“Famine”
The movement of conventional 3D objects is based on three axes
If we only extract one of them, what will it look like?
- Extract the X -Y axis, and the object shows a feeling that is compressed in front of the perspective.
“Super Mario 2”
- Extract the X -Z axis, and the object shows a feeling of being overlooking.
“Eight Fangs Traveler”
- First of the first 2D project
- and then draw a 2D map to add a collision device to trees and other
I used tile maps and flat palettes to create here
- Create a character Sprite and add a collision device, animation, rigid body, an animation that edit characters walking in the animation in different directions
- Write Playermovement.cs script, control the character movement
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class PlayMovement1 : MonoBehaviour
{
public float speed = 5;
private float inputX;
private float inputY;
private float stopX, stopY;
private Animator animator;
new private Rigidbody2D rigidbody;
private Vector3 offset;
// Start is called before the first frame update
void Start()
{
offset = Camera.main.transform.position - transform.position;
rigidbody = GetComponent<Rigidbody2D>();
animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
inputX = Input.GetAxisRaw("Horizontal");
inputY = Input.GetAxisRaw("Vertical");
Vector2 input = new Vector2(inputX, inputY).normalized;
rigidbody.velocity = input * speed;
if(input != Vector2.zero)
{
animator.SetBool("isMoving", true);
stopX = inputX;
stopY = inputY;
}
else
{
animator.SetBool("isMoving", false);
}
animator.SetFloat("InputX", stopX);
animator.SetFloat("InputY", stopY);
Camera.main.transform.position = transform.position + offset;
}
}
-
Adjust the perspective, turn the 2D view to 3D view, and the camera becomes 45 ° down the perspective.
-
At this time, the scene object is not standing. You need to set a script for the scene object and character. The rotation angle of the camera is the same as the camera and set the camera and the character’s movement synchronization.
//FaceCamera.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FacingCamrea : MonoBehaviour
{
Transform[] childs = null;
// Start is called before the first frame update
void Start()
{
childs = new Transform[transform.childCount];
for (int i = 0; i < transform.childCount; i++)
{
childs[i] = transform.GetChild(i);
}
}
// Update is called once per frame
void Update()
{
for(int j = 0; j < childs.Length; j++)
{
childs[j].rotation = Camera.main.transform.rotation;
}
}
}
Unity2.5D game implementation
https://download.csdn.net/download/Tom870223050/85550510