Search Unity

Need Help Side jumping?

Discussion in 'Scripting' started by sean4mvo, Jan 30, 2015.

  1. sean4mvo

    sean4mvo

    Joined:
    Jan 5, 2015
    Posts:
    15
    Here's some help with Side jumping from left to right, hope this helps! Please give feedback.
     
    Last edited: Jan 30, 2015
  2. sean4mvo

    sean4mvo

    Joined:
    Jan 5, 2015
    Posts:
    15
    So I think this is the script but I'm not sure if its legit, is it C# or JAva?


    1. publicenumDodgeDirection{Right,Left,Forward,Backward}
    2. // This vector is essential if you want to have variants dodging amounts/forces, it represents how much the player will go to the side, up and forward
    3. // left: -x, right: +x, up: +y, down: -y, forward: +z, backward: -z. Don't worry you'll understand in a moment
    4. // if you don't want to have different forces applied to your player when he dodges left/right, forward/backward, just get rid of this vector and use a float variable instead
    5. publicVector3 dodge =newVector3(5,5,5);
    6. // This is the dodging method, you just give it a direction and it will handle the rest using the `dodge` vector we previously defined.
    7. publicvoidDodge(DodgeDirection dir)
    8. {
    9. switch(dir)
    10. {
    11. caseDodgeDirection.Right:
    12. rigidbody.AddForce(_transform.right * dodge.x + _transform.up * dodge.y,ForceMode.Impulse);
    13. break;
    14. caseDodgeDirection.Left:
    15. rigidbody.AddForce(-_transform.right * dodge.x + _transform.up * dodge.y,ForceMode.Impulse);
    16. break;
    17. caseDodgeDirection.Forward:
    18. rigidbody.AddForce(_transform.forward * dodge.z + _transform.up * dodge.y,ForceMode.Impulse);
    19. break;
    20. caseDodgeDirection.Backward:
    21. rigidbody.AddForce(-_transform.forward * dodge.z + _transform.up * dodge.y,ForceMode.Impulse);
    22. break;
    23. }
    24. }
    25. // Since we're gonna be dealing with a rigidbody and forces, we might as well use FixedUpdate
    26. // I used 'l', 'j', 'i' and 'k' to dodge left, right, forward and backward (respectively)
    27. // If I were you and using WASD controls, I would dodge left by double tapping 'A', right by double tapping 'D' etc. (With a threshold I define)
    28. voidFixedUpdate()
    29. {
    30. if(Input.GetKeyDown("l"))
    31. Dodge(DodgeDirection.Right, dodge);
    32. if(Input.GetKeyDown("j"))
    33. Dodge(DodgeDirection.Left, dodge);
    34. if(Input.GetKeyDown("i"))
    35. Dodge(DodgeDirection.Forward, dodge);
    36. if(Input.GetKeyDown("k"))
    37. Dodge(DodgeDirection.Backward, dodge);
    38. }
     
  3. CaoMengde777

    CaoMengde777

    Joined:
    Nov 5, 2013
    Posts:
    813
    its c# ..

    use the code dealy to paste it... (click icon to left of save disc icon, and pick code, paste code in there)

    Code (CSharp):
    1. if ( stuff = stuff)
    2. {
    3.      //things
    4. }