Hi, mates,
I’m feeling a bit desperate because last 2 hours I’ve spent searching for a solution, but didn’t succeed.
I tried to develop an easy script to check if the Player isGrounded.
But the problem is that when I run the project my player is “floating” in the air, like no gravity is applied. (Rigidbody2D is attached)
###upd:
I’ve increased the Gravity Scale of the player, so he finally landed, but the script still does not set grounded = true, i guess the problem is in the Physics.Linecast()
Code where I try using the Linecast function never sets grounded or jump to true
void Update()
{
myMaskLayer = 1 << LayerMask.NameToLayer("Ground");
grounded = Physics2D.Linecast(transform.position, groundCheck.position, myMaskLayer);
if(Input.GetButtonDown("Jump") && grounded){
jump = true;
}
}
A screenshot with configurations from Unity
[22492-testlevel.unity±+pixeljourney±+pc,+mac+&+linux+standalone+2014-02-20+21-12-03.jpg|22492]
#Thank you!