Search Unity

How to make a Jump while standing and move on X Axis smoothly?

Discussion in 'Scripting' started by HugoBardo, Aug 29, 2014.

  1. HugoBardo

    HugoBardo

    Joined:
    Aug 26, 2014
    Posts:
    1
    Hi,

    i'm trying to do a jump while standing. I would like that my char after pressing SPACE did not jump only on the vertical axis but also move forward of a certain value.

    to explain me better you remember the prince of persia jump when he was standing?

    This is my normal jump code that works well for jump when i'm running

    rigidbody2D.AddForce(new Vector2(0,JumpForce));

    I tried to do this for jumping while standing supposing that the first value was the movement on the X:

    rigidbody2D.AddForce(new Vector2(desired value,JumpForce));

    but did not work.

    You have ideas?
     
  2. FlaSh-G

    FlaSh-G

    Joined:
    Apr 21, 2010
    Posts:
    212
    "Did not work" is not really a productive thing to say. Did your character just jump up instead of jumping forward? Did you get any errors? Did the editor crash?
    Did not work can mean anything. So it means nothing.
     
  3. bloeys

    bloeys

    Joined:
    Aug 26, 2014
    Posts:
    57
    Hi,

    Well first of all a bit more of your code would be useful, like where it is being called.

    The first code you used won't work because you are adding 0 force to the x axis so the 'char' will only jump up.
    The second code 'should' work but as it's a jump code I expect it to be called only once, not in an update, this would mean that if the force is too small it's effect won't be seen.

    I would recommend you try something like this:

    Code (CSharp):
    1. rigidbody2D.AddForce(new Vector2(desiredForceOnX, desiredForceOnY), ForceMode2D.Impulse);
    Try this code instead and play with the values.

    Hope that helps :)

    Note: Giving more information might make it easier for us to help ;)