unity3d - 在统一 2d 中,我的角色有时会跳得太厉害
问题描述
我的角色跳跃在直线对撞机中运行良好,然后我注意到每次我的角色在曲线形对撞机中跳跃时,我的跳跃总是异常强烈。我怎样才能解决这个问题?我将在下面提供跳跃运动的初始代码。
这是img:
这是跳转代码:
float checkgroundradius = 0.50f;
public bool isgrounded2;
public Transform grouncheckslot;
public LayerMask LM;
public float JumpPower;
public float movespeed;
Rigidbody2d RB;
void Update () {
if (isgrounded && Input.GetKeyDown(KeyCode.UpArrow))
{
isgrounded = false;
jumping = true;
myanim.SetBool("groundedanim", isgrounded);
myrb.AddForce(new Vector2(0, jumpower));
}
}
void FixedUpdate()
{
isgrounded = Physics2D.OverlapCircle(checkslot.position, groundradius, LM);
myanim.SetBool("groundedanim", isgrounded);
myanim.SetFloat("verticalspeed", myrb.velocity.y);
float move = Input.GetAxis ("Horizontal");
RB.velocity = new Vector 2 (move * movespeed, RB.velocity.y);
}
解决方案
跳上斜坡时,您Physics2D.OverlapCircle
与斜坡相交,从而使isgrounded=true
,如果按下向上箭头,则使您施加更大的力。
解决方案可能是在跳跃之前检查您的角色是否已经向上移动
if (isgrounded && Input.GetKeyDown(KeyCode.UpArrow) && myrb.velocity.y <= 0.0f)
这样,如果您已经向上移动,您将不会再次跳跃。
也许您可以玩一个较小的groundradius
和/或尝试checkslot.position
以不以相同方式与斜坡相交的方式移动。
推荐阅读
- mysql - 如何从 MySQL 中的数据向量创建表列?
- c - 制作头文件,编译它们并在C中运行
- r - R ggplot 2图例边框问题
- javascript - 使用 Mailgun 从 Base64 字符串发送 pdf 附件
- python - 在元音+周围辅音处拆分字符串
- javascript - 如何通过他们的 ID 和给出的消息到达不和谐中的机器人 dms 一个人的位置
- ruby-on-rails - 使用 Rails.cache 时 Rspec 测试失败,但如果我执行 binding.pry 则通过
- python - __init__() 缺少 1 个必需的位置参数 'master'
- javascript - 更改 SpeechSynthesis 语音不起作用
- python - 在 OpenCV 和 Python 中控制视频流的对比度和亮度