Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[角色漂浮]跳跃问题 #1

Open
RSzyg opened this issue Dec 1, 2018 · 0 comments
Open

[角色漂浮]跳跃问题 #1

RSzyg opened this issue Dec 1, 2018 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@RSzyg
Copy link
Member

RSzyg commented Dec 1, 2018

角色移动时漂浮,跳跃会出现蜜汁bug,跳不高或者跳不起来,在地图浮板上十分明显,猜测是漂浮地面判断问题
可能的问题代码:

  1. 判断角色是否漂浮
// Judge if float over ground
if (isFloating)
{
	StopFloating();
	colliders =
		Physics2D.OverlapCircleAll(floatCheck.position, checkRadius, groundLayer);
	for (int i = 0; i < colliders.Length; i++)
	{
		if (colliders[i].gameObject != gameObject)
		{
			KeepFloating();
		}
	}
}
  1. 角色漂浮处理

// Handle floating
if (horizonMove != 0)
{
	// Make or keep player floating
	if ((isGrounded || isFloating) && !jump)
	{
		KeepFloating();
	}
}
else
{
	StopFloating();
}
private void KeepFloating()
{
	rb2d.gravityScale = 0f;
	isGrounded = false;
	isFloating = true;
	if (transform.position.y < floatPos)
	{
		transform.position += Vector3.up * floatSpeed;
	}
	if (transform.position.y > floatPos)
	{
		transform.position =
			new Vector3(transform.position.x, floatPos, transform.position.z);
	}
}
  1. 跳跃处理
// Handle jump
if (jump)
{
	if (isGrounded || isFloating)
	{
		isGrounded = false;
		StopFloating();
		rb2d.AddForce(Vector2.up * jumpForce);
	}
}
@RSzyg RSzyg added the bug Something isn't working label Dec 1, 2018
@RSzyg RSzyg changed the title 角色移动漂浮跳跃问题 [角色漂浮]跳跃问题 Dec 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants