Skip to main content
Commonmark migration
Source Link

I'm not sure you can use key combinations as input, so you may need to set up two buttons and then check for a GetButton on the shift during a GetButtonDown on the W.

Input manager configuration:

Sprint
  Positive Button: w
Shift
  Positive Button: left shift
  Alt Positive Button: right shift

That will allow either shift to be used. If you don't want that, leave the Alt Positive Button blank. Negative buttons and other alt buttons can be left blank. All the other settings should be fine.

Then your code would look something like this:

if (isGrounded && Input.GetButton("Shift") && Input.GetButtonDown("Sprint")) {
    isRunning = true;
}

if (Input.GetButtonUp("Shift") || Input.GetButtonUp("Sprint")) {
    isRunning = false;
}

Or, as @DMGregory pointed out, the code can be simplified to one line:

isRunning = isGrounded && Input.GetButton("Shift");

This has slightly different behavior, since it triggers when holding w first and then beginning to hold shift, whereas the first code example only triggers when you hold shift first. I don't know exactly what controls you want, but the second code example is probably better.

Edit

##Edit ItIt turns out I was overthinking this. You already have W assigned to your Vertical axis, which you are using. Just have isRunning equal the state of the shift key.

//Sprint
//  Positive Button: left shift
//  Alt Positive Button: right shift

isRunning = GetButton("Sprint");

I'm not sure you can use key combinations as input, so you may need to set up two buttons and then check for a GetButton on the shift during a GetButtonDown on the W.

Input manager configuration:

Sprint
  Positive Button: w
Shift
  Positive Button: left shift
  Alt Positive Button: right shift

That will allow either shift to be used. If you don't want that, leave the Alt Positive Button blank. Negative buttons and other alt buttons can be left blank. All the other settings should be fine.

Then your code would look something like this:

if (isGrounded && Input.GetButton("Shift") && Input.GetButtonDown("Sprint")) {
    isRunning = true;
}

if (Input.GetButtonUp("Shift") || Input.GetButtonUp("Sprint")) {
    isRunning = false;
}

Or, as @DMGregory pointed out, the code can be simplified to one line:

isRunning = isGrounded && Input.GetButton("Shift");

This has slightly different behavior, since it triggers when holding w first and then beginning to hold shift, whereas the first code example only triggers when you hold shift first. I don't know exactly what controls you want, but the second code example is probably better.

##Edit It turns out I was overthinking this. You already have W assigned to your Vertical axis, which you are using. Just have isRunning equal the state of the shift key.

//Sprint
//  Positive Button: left shift
//  Alt Positive Button: right shift

isRunning = GetButton("Sprint");

I'm not sure you can use key combinations as input, so you may need to set up two buttons and then check for a GetButton on the shift during a GetButtonDown on the W.

Input manager configuration:

Sprint
  Positive Button: w
Shift
  Positive Button: left shift
  Alt Positive Button: right shift

That will allow either shift to be used. If you don't want that, leave the Alt Positive Button blank. Negative buttons and other alt buttons can be left blank. All the other settings should be fine.

Then your code would look something like this:

if (isGrounded && Input.GetButton("Shift") && Input.GetButtonDown("Sprint")) {
    isRunning = true;
}

if (Input.GetButtonUp("Shift") || Input.GetButtonUp("Sprint")) {
    isRunning = false;
}

Or, as @DMGregory pointed out, the code can be simplified to one line:

isRunning = isGrounded && Input.GetButton("Shift");

This has slightly different behavior, since it triggers when holding w first and then beginning to hold shift, whereas the first code example only triggers when you hold shift first. I don't know exactly what controls you want, but the second code example is probably better.

Edit

It turns out I was overthinking this. You already have W assigned to your Vertical axis, which you are using. Just have isRunning equal the state of the shift key.

//Sprint
//  Positive Button: left shift
//  Alt Positive Button: right shift

isRunning = GetButton("Sprint");

I'm not sure you can use key combinations as input, so you may need to set up two buttons and then check for a GetButton on the shift during a GetButtonDown on the W.

Input manager configuration:

Sprint
  Positive Button: w
Shift
  Positive Button: left shift
  Alt Positive Button: right shift

That will allow either shift to be used. If you don't want that, leave the Alt Positive Button blank. Negative buttons and other alt buttons can be left blank. All the other settings should be fine.

Then your code would look something like this:

if (isGrounded && Input.GetButton("Shift") && Input.GetButtonDown("Sprint")) {
    isRunning = true;
}

if (Input.GetButtonUp("Shift") || Input.GetButtonUp("Sprint")) {
    isRunning = false;
}

Or, as @DMGregory pointed out, the code can be simplified to one line:

isRunning = isGrounded && Input.GetButton("Shift") && Input.GetButton("Sprint");

This has slightly different behavior, since it triggers when holding w first and then beginning to hold shift, whereas the first code example only triggers when you hold shift first. I don't know exactly what controls you want, but the second code example is probably better.

##Edit It turns out I was overthinking this. You already have W assigned to your Vertical axis, which you are using. Just have isRunning equal the state of the shift key.

//Sprint
//  Positive Button: left shift
//  Alt Positive Button: right shift

isRunning = GetButton("Sprint");

I'm not sure you can use key combinations as input, so you may need to set up two buttons and then check for a GetButton on the shift during a GetButtonDown on the W.

Input manager configuration:

Sprint
  Positive Button: w
Shift
  Positive Button: left shift
  Alt Positive Button: right shift

That will allow either shift to be used. If you don't want that, leave the Alt Positive Button blank. Negative buttons and other alt buttons can be left blank. All the other settings should be fine.

Then your code would look something like this:

if (isGrounded && Input.GetButton("Shift") && Input.GetButtonDown("Sprint")) {
    isRunning = true;
}

if (Input.GetButtonUp("Shift") || Input.GetButtonUp("Sprint")) {
    isRunning = false;
}

Or, as @DMGregory pointed out, the code can be simplified to one line:

isRunning = isGrounded && Input.GetButton("Shift") && Input.GetButton("Sprint");

This has slightly different behavior, since it triggers when holding w first and then beginning to hold shift, whereas the first code example only triggers when you hold shift first. I don't know exactly what controls you want, but the second code example is probably better.

##Edit It turns out I was overthinking this. You already have W assigned to your Vertical axis, which you are using. Just have isRunning equal the state of the shift key.

//Sprint
//  Positive Button: left shift
//  Alt Positive Button: right shift

isRunning = GetButton("Sprint");

I'm not sure you can use key combinations as input, so you may need to set up two buttons and then check for a GetButton on the shift during a GetButtonDown on the W.

Input manager configuration:

Sprint
  Positive Button: w
Shift
  Positive Button: left shift
  Alt Positive Button: right shift

That will allow either shift to be used. If you don't want that, leave the Alt Positive Button blank. Negative buttons and other alt buttons can be left blank. All the other settings should be fine.

Then your code would look something like this:

if (isGrounded && Input.GetButton("Shift") && Input.GetButtonDown("Sprint")) {
    isRunning = true;
}

if (Input.GetButtonUp("Shift") || Input.GetButtonUp("Sprint")) {
    isRunning = false;
}

Or, as @DMGregory pointed out, the code can be simplified to one line:

isRunning = isGrounded && Input.GetButton("Shift");

This has slightly different behavior, since it triggers when holding w first and then beginning to hold shift, whereas the first code example only triggers when you hold shift first. I don't know exactly what controls you want, but the second code example is probably better.

##Edit It turns out I was overthinking this. You already have W assigned to your Vertical axis, which you are using. Just have isRunning equal the state of the shift key.

//Sprint
//  Positive Button: left shift
//  Alt Positive Button: right shift

isRunning = GetButton("Sprint");
added 302 characters in body
Source Link
tyjkenn
  • 2.6k
  • 18
  • 24

I'm not sure you can use key combinations as input, so you may need to set up two buttons and then check for a GetButton on the shift during a GetButtonDown on the W.

Input manager configuration:

Sprint
  Positive Button: w
Shift
  Positive Button: left shift
  Alt Positive Button: right shift

That will allow either shift to be used. If you don't want that, leave the Alt Positive Button blank. Negative buttons and other alt buttons can be left blank. All the other settings should be fine.

Then your code would look something like this:

if (isGrounded && Input.GetButton("Shift") && Input.GetButtonDown("Sprint")) {
    isRunning = true;
}

if (Input.GetButtonUp("Shift") || Input.GetButtonUp("Sprint")) {
    isRunning = false;
}

Or, as @DMGregory pointed out, the code can be simplified to one line:

isRunning = isGrounded && Input.GetButton("Shift") && Input.GetButton("Sprint");

This has slightly different behavior, since it triggers when holding w first and then beginning to hold shift, whereas the first code example only triggers when you hold shift first. I don't know exactly what controls you want, but the second code example is probably better.

##Edit It turns out I was overthinking this. You already have W assigned to your Vertical axis, which you are using. Just have isRunning equal the state of the shift key.

//Sprint
//  Positive Button: left shift
//  Alt Positive Button: right shift

isRunning = GetButton("Sprint");

I'm not sure you can use key combinations as input, so you may need to set up two buttons and then check for a GetButton on the shift during a GetButtonDown on the W.

Input manager configuration:

Sprint
  Positive Button: w
Shift
  Positive Button: left shift
  Alt Positive Button: right shift

That will allow either shift to be used. If you don't want that, leave the Alt Positive Button blank. Negative buttons and other alt buttons can be left blank. All the other settings should be fine.

Then your code would look something like this:

if (isGrounded && Input.GetButton("Shift") && Input.GetButtonDown("Sprint")) {
    isRunning = true;
}

if (Input.GetButtonUp("Shift") || Input.GetButtonUp("Sprint")) {
    isRunning = false;
}

Or, as @DMGregory pointed out, the code can be simplified to one line:

isRunning = isGrounded && Input.GetButton("Shift") && Input.GetButton("Sprint");

This has slightly different behavior, since it triggers when holding w first and then beginning to hold shift, whereas the first code example only triggers when you hold shift first. I don't know exactly what controls you want, but the second code example is probably better.

I'm not sure you can use key combinations as input, so you may need to set up two buttons and then check for a GetButton on the shift during a GetButtonDown on the W.

Input manager configuration:

Sprint
  Positive Button: w
Shift
  Positive Button: left shift
  Alt Positive Button: right shift

That will allow either shift to be used. If you don't want that, leave the Alt Positive Button blank. Negative buttons and other alt buttons can be left blank. All the other settings should be fine.

Then your code would look something like this:

if (isGrounded && Input.GetButton("Shift") && Input.GetButtonDown("Sprint")) {
    isRunning = true;
}

if (Input.GetButtonUp("Shift") || Input.GetButtonUp("Sprint")) {
    isRunning = false;
}

Or, as @DMGregory pointed out, the code can be simplified to one line:

isRunning = isGrounded && Input.GetButton("Shift") && Input.GetButton("Sprint");

This has slightly different behavior, since it triggers when holding w first and then beginning to hold shift, whereas the first code example only triggers when you hold shift first. I don't know exactly what controls you want, but the second code example is probably better.

##Edit It turns out I was overthinking this. You already have W assigned to your Vertical axis, which you are using. Just have isRunning equal the state of the shift key.

//Sprint
//  Positive Button: left shift
//  Alt Positive Button: right shift

isRunning = GetButton("Sprint");
added 437 characters in body
Source Link
tyjkenn
  • 2.6k
  • 18
  • 24
Loading
added 22 characters in body
Source Link
tyjkenn
  • 2.6k
  • 18
  • 24
Loading
Source Link
tyjkenn
  • 2.6k
  • 18
  • 24
Loading