- Home /
Can't move when fall from high
Hi!! I'm doing a platform game, my first game and when I fall from very high with my player, he gets stuck on the ground and I can't move. Is there any solution to this? Has it happened to someone already? Notice that when in my player's rigidbody I put continuous in collision detection it doesn't stuck. But the problem is that I have to leave it in discrete. Because with continuous it doesn't let me kill enemies. I don't pass the script because I don't know which one i should pass and I have several, I have the script of the player, of the enemy, of player's feet which is for kill the enemy when I touch him with feets. If it is necessary to put some code I put it but maybe the same thing happened to someone. The provisory solution was this:
public Rigidbody2D playerBody;
public PlayerLogic Player;
Update(){
if (Input.GetKeyDown("l"))
{
Player.playerBody.transform.position = new Vector3(Player.playerBody.position.x + 1, Player.playerBody.position.y + 1, 100);
}
}
But of course that is not a real solution because it would be great to don't have to press a key to move if i get stuck.
Answer by JackReivaj · Mar 21, 2021 at 07:59 PM
I thinks i solved with this code but i still testing.
public Rigidbody2D bodyPlayer;
public bool OnTheFloor = false;
Update () {
if (bodyPlayer.velocity.y <-50f)
{
bodyPlayer.gravityScale = 1;
if (OnTheFloor)
{
bodyPlayer.gravityScale = 5;
} else if ((bodyPlayer.velocity.y> 50f))
{
bodyPlayer.gravityScale = 1;
if (OnTheFloor)
{
bodyPlayer.gravityScale = 5;
}
}
}
if (OnTheFloor)
{
bodyPlayer.gravityScale = 5;
}
}