- Home /
Question by
PapperWing · Dec 17, 2014 at 09:55 PM ·
gravityair
2d GameObject is sticked to block in air
Hi,
I am creating running game, where player is pushed forward. But when it collides in air, it doesn't fall down but stay on position in air.
Here is my movement script: public class Player : MonoBehaviour {
public float maxSpeed = 10f;
public float minSpeed = 5f;
public float addValue= 0.1f;
public float speed;
public float jumpForce;
public bool grounded = false;
public Transform groundCheck;
private float groundRadius = 0.1f;
public LayerMask whatIsGround;
void Start () {
speed = 0f;
}
void FixedUpdate () {
grounded = Physics2D.OverlapCircle (groundCheck.position, groundRadius, whatIsGround);
move ();
}
void move(){
if (speed < minSpeed || (speed < maxSpeed && !grounded) )
speed += addValue;
if (speed > minSpeed && grounded) {
speed -= addValue;
}
this.rigidbody2D.velocity = new Vector2(speed, this.rigidbody2D.velocity.y);
}
void Update(){
if(grounded && Input.GetKeyDown ("space")){
rigidbody2D.AddForce (new Vector2 (0, jumpForce));
}
}
I would really appreciate, if someone could help me with this.
Best regards, Jakub Peschel
Comment
Your answer
Follow this Question
Related Questions
Enemy Ai Problem with the collider and gravity 1 Answer
Rigidbody--Addforce on a Spherical Platform(A Globe) 2 Answers
Physics gravity appears very weak 2 Answers
Simulate gravity on rigidbody 1 Answer