- Home /
This question was
closed Jun 15, 2019 at 09:44 PM by
adovehv for the following reason:
Other
Question by
adovehv · Jun 14, 2019 at 03:48 PM ·
raycastplayerraycastingraycasthit2d
2d Raycast not work
Hi! i need to detect the ground with a raycast to activate the falling animation, i use this code, but not work, the code detect the ground all time. Thanks! :)
public class Player : MonoBehaviour
{
public float distanceGround;
public bool isGrounded = false;
void Start()
{
distanceGround = GetComponent<Collider2D>().bounds.extents.y;
}
void FixedUpdate()
{
//Movement
rb2d.MovePosition(rb2d.position + mov * speed * Time.deltaTime);
//Falling raycast
if (!Physics2D.Raycast(transform.position, -Vector2.up, + 0.1f))
{
isGrounded = false;
print("air");
}
else
{
isGrounded = true;
print("ground");
}
Comment
Answer by zapextreme · Jun 14, 2019 at 10:55 PM
Try going to Edit > Project Settings > Physics 2D and uncheck Queries Start In Colliders. It should look like this:
img.png
(35.1 kB)
Follow this Question
Related Questions
Player Raycast Does Not Compute 0 Answers
Is there a problem with my raycast? 1 Answer
What's wrong with my RaycastHit2D? 1 Answer