have 3rd person make a side jump

Hi All,

I am trying to make my player side jump since a few days.
For the normal jump I use the classic:

if (Input.GetButtonDown("Jump"))
            rigidbody.velocity = new Vector3(0, 10, 0);

but I cant find any way to have him jump and move side ways (left or right)

I tried affecting Velocity, AddForce, AddRelativeForce,…
using Vector3.right, (float x, float y, float z),…
but whatever I try, he never moves side ways with those.

If any of you would have a hint on how to do this, it would greatly help me.


I assume that you’re not using the standard character controller to learn and implement everything on your own. Check out this series from Quilly where he makes a character controller from scratch, he covers a lot of things in really great detail, I’m sure you will resolve your problem there. Helped me a lot, hope it does the same for you :slight_smile:

EDIT: OK so well Quilly didn’t cut it for you, that’s why we’re here :slight_smile:

It was easier than I thought, I did it with a rigidbody attached to my player, it worked really nice for me. Here you go:

// This enum is for convenience, you can go without it if you want, I like to stay organized :)
public enum DodgeDirection { Right, Left, Forward, Backward }

// 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
// left: -x, right: +x, up: +y, down: -y, forward: +z, backward: -z. Don't worry you'll understand in a moment
// 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
public Vector3 dodge = new Vector3(5, 5, 5);

// This is the dodging method, you just give it a direction and it will handle the rest using the `dodge` vector we previously defined.
public void Dodge(DodgeDirection dir)
    	switch (dir) 
    		case DodgeDirection.Right:
    			rigidbody.AddForce(_transform.right * dodge.x + _transform.up * dodge.y, ForceMode.Impulse);
    		case DodgeDirection.Left:
    			rigidbody.AddForce(-_transform.right * dodge.x + _transform.up * dodge.y, ForceMode.Impulse);
    		case DodgeDirection.Forward:
    			rigidbody.AddForce(_transform.forward * dodge.z + _transform.up * dodge.y, ForceMode.Impulse);
    		case DodgeDirection.Backward:
    			rigidbody.AddForce(-_transform.forward * dodge.z + _transform.up * dodge.y, ForceMode.Impulse);

// Since we're gonna be dealing with a rigidbody and forces, we might as well use FixedUpdate
// I used 'l', 'j', 'i' and 'k' to dodge left, right, forward and backward (respectively)
// 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)
void FixedUpdate()
    if (Input.GetKeyDown("l"))
        	Dodge(DodgeDirection.Right, dodge);
    if (Input.GetKeyDown("j"))
        	Dodge(DodgeDirection.Left, dodge);
    if (Input.GetKeyDown("i"))
        	Dodge(DodgeDirection.Forward, dodge);
    if (Input.GetKeyDown("k"))
        	Dodge(DodgeDirection.Backward, dodge);

Couple of notes:

  1. In my test environment, I was using
    a capsule collider for my player so
    I had to constrain all the rotations
    in the rigidbody component,
    because since I’m adding force, the
    capsule would get knocked out and
    thrown to the ground (kinda cool
    effect if you want fighting in your
    game) - So no rotation from the
    rigidbody, I handled rotation
  2. I tried all the possible types of
    forces, only Impulse and
    VelocityChange seemed to do the
    trick, while Force and
    Acceleration didn’t seem to have
    any effect.
  3. Wondering about _transform? - I
    always like to cache my transform
    component if I’m gonna be using it a
    lot, because when you do
    transform, you’re actually calling
    GetComponent<Transform>() - which
    isn’t nice to call so many times. (I usually cache in Start or Awake)
  4. Make sure you handle the rotation of
    your player well, let me know if you
    have trouble with that - You could
    use Quilly’s code for that, works
    like charm.

Let me know how it goes, hope I helped :slight_smile: