Search Unity

Applying velocity to rigidbody2D not working properly

Discussion in '2D' started by mothercow5, Jun 22, 2019.

  1. mothercow5

    mothercow5

    Joined:
    Jun 22, 2019
    Posts:
    1
    I'm trying to make an alternate jumping mechanic for a 2D platforming game that works kind of like a bounce. I want the player to be able to aim their bounce with the mouse then click and have the character fly up with the y-direction inverted (right now it's not inverted in my script for testing).
    upload_2019-6-22_17-0-27.png
    This is the method in my movement controller that enables the bounce. m_BounceForce is just a float.
    upload_2019-6-22_17-2-8.png
    I use this script to initiate the bounce as well as update the aim direction.

    My problem is that when I play the game and aim the mouse 45 deg from the character, for example, I expect it to shoot up at 45 deg and follow a parabolic trajectory to the ground. But, what happens is that the character will move towards my mouse for a fraction of a second and then start going up, almost following an upside-down parabola, then falls to the ground normally.

    Also, if I aim straight above the character, it goes a lot further in the y-direction than it does in the x-direction when I aim directly to one side.

    I've tried doing the same thing using .addForce(new Vector2(direction.x * m_BounceForce, direction.y * m_BounceForce), and it behaves exactly the same way.

    Please help.