【Unity】从0到1的横版2d制作笔记-DAY3

确定碰撞体积

选择rigidbody2d,创建player重力
创建player碰撞体积
创建瓦片地图碰撞体积
使平台变成一个整体
设置Body Type为Static(避免平台也因为重力影响下落)
回到Player,在Rigidbody2D中设置为冻结旋转


Player设置参考

Platform设置参考

我做的时候其实是有一点bug的,比如在设置碰撞体积的时候即使两个都有碰撞体积(平台和人物),也是会一直下坠的,结果后来发现原因是因为平台和人物位置设定的有问题。乍一看没什么,但是事实上人物的脚在平台的里面的位置,所以会一直掉下去。 修改一下位置即可。

使用Input System来监听用户输入

zsbd

添加PlayerController
添加

修改Configuration
windows->Packet Manager

创建配置文件
zbsd
zsbd
如果想要创建一套手柄的输入法


创建一个keyboard和gamepad


做完保存然后删除inputcontrols(没错 只是练习qvq)

使用Unity的Input Control来控制人物移动

选择create actions,将创建的文件存档Input System文件夹

PlayerController.cs

cs 复制代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerController : MonoBehaviour
    //继承在MonoBehavior类中
{
    // Start is called before the first frame update
    public PlayerInputControl inputControl;
    public Vector2 inputDirection;//存储Vector2变量
    private void Awake()
    {
        inputControl = new PlayerInputControl();
        //实例化
    }
    private void OnEnable()
    {
        inputControl.Enable();
    }
    private void OnDisable()
    {
        inputControl.Disable();
    }
    private void Update()
    {
        inputDirection = inputControl.Gameplay.Move.ReadValue<Vector2>();
    }
}
相关推荐
Cathy Bryant2 小时前
球极平面投影
经验分享·笔记·数学建模
Larry_Yanan3 小时前
QML学习笔记(三十一)QML的Flow定位器
java·前端·javascript·笔记·qt·学习·ui
The_Killer.3 小时前
近世代数(抽象代数)详细笔记--环(也有域的相关内容)
笔记·学习·抽象代数·
Larry_Yanan3 小时前
QML学习笔记(三十)QML的布局器(Layouts)
c++·笔记·qt·学习·ui
不会kao代码的小王4 小时前
突破机房围墙:openEuler设备的公网管理实战指南
开发语言·数据库·笔记
He BianGu4 小时前
【笔记】WPF中如何的动态设置DataGridTextColumn是否显示
笔记·wpf
_李小白6 小时前
【OPENGL ES 3.0 学习笔记】第一天:认识渲染管道
笔记·学习
bnsarocket6 小时前
Verilog和FPGA的自学笔记4——多路选择器(always语句)
笔记·fpga开发·编程·verilog·自学·硬件编程
你也渴望鸡哥的力量么9 小时前
爬虫学习笔记
笔记·爬虫·学习
日更嵌入式的打工仔9 小时前
InitLWIP() 初始化
笔记·嵌入式硬件·学习