直接复制粘贴使用即可 using UnityEngine; using UnityEngine.Events; public class CharacterController2D : MonoBehaviour { public float jumpForce = 400f; // 弹跳力 public bool canAirControl = false; // 在空中时,是否能控制 public LayerMask groundMask; // 定义哪一个Layer是地面 public Transform m_Gr...
通常,所有类人角色都使用角色控制器 (Character Controller) 来实现。 角色控制器 (Character Controller) 本质上是非物理性的,如果要将真实物理现象应用于角色,比如在绳索上摇摆、由大岩石推动,则必须使用刚体 (Rigidbody),这样才能对角色使用关节 (Joint) 和力。 角色控制器 (Character Controller) 始终沿 Y 轴对...
接着新建一个CharacterController2D脚本,用于控制角色。将该脚本挂载到玩家的身上。 检测地面 为了实现跳跃功能,我们需要检测地面的存在,如果玩家处于地面,并且按下了跳跃键,才能跳跃。 检测地面有多重实现方式,例如为角色添加子物体的触发器,用触发器来检测地面,也可以向脚下发射射线,也可以对一个区域进行碰撞检测,看看...
地址:https://github.com/prime31/CharacterController2D 博主使用这个控制器的主要目的是为了做一款平台动作类游戏,因此也会着重说一些制作使用途中遇到的问题以及解决方法。 先看一下组件挂载在GameObject上之后可以设定的属性: 可以看到这里和CharacterController一样也有Skin Width这个选项,这个选项会影响角色控制器检测碰...
首先需要先实现炸弹包和医药包的组合物体,实现下落和着落两个动画效果。 炸弹包 下落动画为实现物体左右摆动的效果,着陆动画为降落伞收起的效果,这个通过Scale来实现,使用land参数来控制两个动画的切换。 组合的父对象添加刚体使其具有重力的效果。 炸弹添加了两个脚本,BombPickup.cs控制炸弹包碰撞的逻辑(被捡起),Bom...
Character Controller Pro is a 2D/3D dynamic rigid body capsule-based character controller. The asset can be divided into two main parts: controller and system: The character controller (core) allows you to handle movement, rotation and size of the character, without you having to worry about ...
移动方法用很多种,比如调用人物的rigidbody2d的AddForce,方法给人物一个加速度等。 这里的方法是,先确定角色的位置,和将要到达的位置,然后在通过Rigidbody2D.MovePosition方法移动。 先提炼下代码。 publicclassCharacterController2D:MonoBehaviour{Rigidbody2Dm_Rigidbody2D;Vector2m_PreviousPosition;Vector2m_CurrentPositio...
移动方法用很多种,比如调用人物的rigidbody2d的AddForce,方法给人物一个加速度等。 这里的方法是,先确定角色的位置,和将要到达的位置,然后在通过Rigidbody2D.MovePosition方法移动。 先提炼下代码。 publicclassCharacterController2D:MonoBehaviour{Rigidbody2Dm_Rigidbody2D;Vector2m_PreviousPosition;Vector2m_CurrentPositio...
In this live training session we will learn how to create a character controller for a 2D platform game which uses custom physics instead of Unity’s built in 2D Physics. Download the asset package here
2D Character Controller Here is a free to use Character Controller for 2D platformer games in Unity. Currently the Controller features: Smooth movement Jumping Crouching Events for setting up animation 2D Physics To learn how to use it check out our video on 2D Movement which can be found on ...