【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>();
    }
}
相关推荐
ReedFoley6 小时前
【笔记】动手学Ollama 第五章 Ollama 在 LangChain 中的使用 - Python 集成
笔记·langchain
Mr Sorry12 小时前
Non-stationary Diffusion For Probabilistic Time Series Forecasting论文阅读笔记
论文阅读·笔记
南猿北者13 小时前
Cmake学习笔记
笔记·学习·策略模式
码小文14 小时前
Altium Designer 22使用笔记(8)---PCB电气约束设置
笔记·嵌入式硬件·硬件工程·ad22
UserNamezhangxi16 小时前
kotlin 协程笔记
java·笔记·kotlin·协程
翻滚的小@强19 小时前
数据挖掘笔记:点到线段的距离计算
人工智能·笔记·数据挖掘
会思考的猴子20 小时前
UE5 PCG 笔记(二) Difference 节点
笔记·ue5
yuxb7320 小时前
Linux 文本处理与 Shell 编程笔记:正则表达式、sed、awk 与变量脚本
linux·笔记·正则表达式
饕餮争锋1 天前
设计模式笔记_行为型_访问者模式
笔记·设计模式·访问者模式
不羁。。1 天前
【撸靶笔记】第七关:GET - Dump into outfile - String
数据库·笔记·oracle