x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

2 Button Player Movement Script - (alternating keys pressed)

I am trying to create a movement script using two alternating button to addMovement to player

PsudeoCode

if (APressed && BReleased) || (BPressed && AReleased) { PlayerMovesForward }

I so far from an accurate thought on how to approach this. Any guidance would be greatly appreciated.

Product Version: UE 4.8
Tags:
more ▼

asked Aug 08 '15 at 01:12 AM in C++ Programming

avatar image

lugaroox22
6 1 2 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

Here is a way to do it

alt text

test15.png (366.1 kB)
more ▼

answered Aug 08 '15 at 10:42 AM

avatar image

Mhousse1247
3.5k 152 29 318

avatar image lugaroox22 Aug 08 '15 at 01:48 PM

Thank you Mhousse1247!

avatar image lugaroox22 Aug 10 '15 at 05:23 PM

Hi @Mhousse1247

I was able to convert the functionality of your (exceedingly helpful) blueprint into C++. I'm still having a problem with the “button mashing” element that I am trying to implement

Currently, if A or B is pressed the player moves forward. I trying to get the player to move forward only when A and B are pressed in consecutive succession (e.g A, B, A,B).

I'm thinking about those old track and field games where you have to press "Left Arrow" and "Right Arrow" on your keyboard super-fast for your Runner to gain momentum and move forward.

This is where I am so far....

 void AMainPlayer::SetupPlayerInputComponent(class UInputComponent* InputComponent)
 {
 Super::SetupPlayerInputComponent(InputComponent);
 
 InputComponent->BindAxis("APressed", this, &AMainPlayer::APressed);
 InputComponent->BindAxis("BPressed", this, &AMainPlayer::BPressed);

 InputComponent->BindAxis("Yaw", this, &AMainPlayer::Yaw);
 InputComponent->BindAxis("Pitch", this, &AMainPlayer::Pitch);
 }

 void AMainPlayer::APressed(float amount)
 {
     if (Controller && keyAlternate == false)
 {
     AddMovementInput(GetActorForwardVector(), amount);

 }
     keyAlternate = true;
 }

 void AMainPlayer::BPressed(float amount)
 {

     if (Controller && keyAlternate == true)
 {
    AddMovementInput(GetActorForwardVector(), amount);
     
 }
      keyAlternate = false;

 }
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Here is a solution

alt text

alt text

test26.png (492.1 kB)
test27.png (231.1 kB)
more ▼

answered Aug 10 '15 at 11:04 PM

avatar image

Mhousse1247
3.5k 152 29 318

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question