- Home /
the ball falls in a straight line sloping
Hello guys ;)
I have a ball with a permanent velocity in x axis and it works untill collision is detected. Everything works fine when the ball goes up (after mouseButtonDown(0)), problem occurs when the ball is supposed to fall becouse of lack of collision. It drops on an inclined plane and it shouldn't be like that. It should be affected only by gravity but it not. Have you guys got any ideas?
Thanks in advance!
void Update ()
{
// Moving RIGHT
if(grounded)
{
rigidbody2D.velocity = new Vector2(speedVelocity, 0);
}
if(Input.GetMouseButtonDown(0))
{
Vector2 currentVelocityY = rigidbody2D.velocity;
if(grounded)
{
rigidbody2D.velocity = new Vector2(currentVelocityY.x, jumpVelocity);
grounded = false;
jumpCounter = 1;
}
else if(!grounded && jumpCounter == 1 && doubleJump > 0)
{
jumpCounter++;
rigidbody2D.velocity = new Vector2(currentVelocityY.x, jumpVelocity);
doubleJump--;
}
}
}
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "Jump Point")
{
grounded = true;
}
}
rigidbody2D.velocity = new Vector2(currentVelocityY.x, jumpVelocity);
Why are you feeding in currentVelocityY.x here? why dident you keep the velocity the same as it was set earlier to.
rigidbody2D.velocity = new Vector2(speedVelocity, jumpVelocity); //but this time just feed in jump velocity to the Y?
I mean this line does not even make sence in its context Vector2 currentVelocityY = rigidbody2D.velocity; your feeding in an (x,y) values into a variable that see$$anonymous$$gly callsfor the Y direction and then never even use it in the Y value in any of the code.
try taking out the currentVelocityY veriable (because I dont think you need it) and just stick with the speedVelocity and JumpVelocity.
let me know if that even makes any difference.
oasisunknown I replaced currentVelocityY with speedVelocity. You're right currentVelocityY changes noghing... But the problem still occurs ;//
I add speedVelocity and jumpVelocity becouse I want the ball to move smoothly right and up in the same time (after clicking). When I delete it, after $$anonymous$$ouseButtonDown the ball's move doens't look real and it's against laws of physics. ;/
It's weird becouse when the ball drops on an inclined plane i still can jump but only once. $$anonymous$$aybe problem is in wrong tagging? cuz when there is no collision detected (no grounded) ball behave correctly...
Your answer
Follow this Question
Related Questions
Falling down the Y-axis? 2 Answers
my character get by jumping 1 Answer
Ball jump on collision problem 1 Answer
Ball jumping when moving over 2 cubes 4 Answers
Wall jumping problem 1 Answer