Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of ground Detection Scheme in Unity

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the example analysis of the ground detection scheme in Unity, which is very detailed and has a certain reference value. Friends who are interested must read it!

1. Ordinary ray

At the character coordinates (usually the soles of the feet), a downward ray is emitted with a length of about 0.2

It is only suitable for simple terrain. The following problems are often encountered in practical use.

When the collider is used to hit the ground, there will be a certain interspersed at some time, so the lowest point of the character may penetrate the ground, the point where you emit the ray may be below the ground, and the ray can't detect the real ground all the time, so the character is always hanging in the air.

When the character is walking the slope, the midpoint of the character may be a short distance from the ground, which is often enough to make the judgment mechanism think that the character has left the ground. If you increase the length of the ray, it will alleviate the ramp problem to some extent, but it will reduce the accuracy of jump judgment: every time the character jumps, there will be a short distance, which is actually off the ground, but still returns isGround = true

Using System.Collections;using System.Collections.Generic;using UnityEngine; public class RaycastTest: MonoBehaviour {private bool isGround = false; private Rigidbody2D myRigidbody2D; void Awake () {myAnimator = GetComponent (); myRigidbody2D = GetComponent ();} void FixedUpdate () {Debug.DrawRay (transform.position, Vector2.down * 0.11f, Color.red); RaycastHit2D hit = Physics2D.Raycast (transform.position, Vector2.down, 0.15f, 1

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report