Weired physics behavior when launching a Ball
When launching a Ball from a object while the object is moving fast the ball ends up launching in the wrong direction.
This only happens when I use my dash move on the player.
if (Input.GetKey(dashKey) && Input.GetKey(downKey) && actualDashCoolDown < 0)
{
transform.position = new Vector3(position.x, Mathf.Clamp(position.y - dashSpeed, minY, maxY));
actualDashCoolDown = dashCoolDown;
}
else if (Input.GetKey(dashKey) && Input.GetKey(upKey) && actualDashCoolDown < 0)
{
transform.position = new Vector3(position.x, Mathf.Clamp(position.y + dashSpeed, minY, maxY));
actualDashCoolDown = dashCoolDown;
}
If the ball is not launched it sticks to the player with this Script:
if (Input.GetKey(KeyCode.Space) && !_launched)
{
_launched = true;
_rb2D.AddForce(new Vector2(launchSpeedX, launchSpeedY));
}
if (!_launched)
{
var position = paddle.gameObject.transform.position;
var paddlePos = new Vector2(position.x + offsetFromPaddle, position.y);
gameObject.transform.position = paddlePos;
}
The launchSpeed for the player is a negativ number.
The player only has a script and polygon collider.
The ball is a Rigidbody 2d with a Dynamic type.
The weired behaviour only occurs when I launch the ball while dashing.
Your answer
Follow this Question
Related Questions
Bullet not moving rigidbody2d,AddForce not working for bullet 1 Answer
Limiting backwards speed 0 Answers
Avoid varying output on same amount of force applied to a Rigidbody2D. 0 Answers
how to addtorque and addforce to same object? 0 Answers
Need help for applying force to rigidbody with .AddForce 0 Answers