Announcement

Collapse
No announcement yet.

Problem whit keybinding

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • replied
    In your question you posted a class named "AOldSchoolArenaFPSCharacter", in a reply you posted "AMyProjectCharacter". Maybe this is the clue?

    When you are calling this function of "AOldSchoolArenaFPSCharacter" you should include the header file of it into your "MyProjectCharacter.cpp".

    Leave a comment:


  • replied
    Originally posted by paccoman View Post
    The function isn't called,this is the full source code:
    header
    // Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
    #pragma once
    #include "GameFramework/Character.h"
    #include "MyProjectCharacter.generated.h"

    UCLASS(config=Game)
    class AMyProjectCharacter : public ACharacter
    {
    GENERATED_UCLASS_BODY()

    //Camera controll bool
    UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = Camera)
    bool TorP;

    //Camera distance variable
    UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = Camera)
    float Distance;

    /** Camera boom positioning the camera behind the character */
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Camera)
    TSubobjectPtr<class USpringArmComponent> CameraBoom;

    /** Follow camera */
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Camera)
    TSubobjectPtr<class UCameraComponent> FollowCamera;

    /** Base turn rate, in deg/sec. Other scaling may affect final turn rate. */
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Camera)
    float BaseTurnRate;

    /** Base look up/down rate, in deg/sec. Other scaling may affect final rate. */
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Camera)
    float BaseLookUpRate;

    protected:

    //Switch T/P
    void Switch_torp();

    /** Called for forwards/backward input */
    void MoveForward(float Value);

    /** Called for side to side input */
    void MoveRight(float Value);

    /**
    * Called via input to turn at a given rate.
    * @param Rate This is a normalized rate, i.e. 1.0 means 100% of desired turn rate
    */
    void TurnAtRate(float Rate);

    /**
    * Called via input to turn look up/down at a given rate.
    * @param Rate This is a normalized rate, i.e. 1.0 means 100% of desired turn rate
    */
    void LookUpAtRate(float Rate);

    /** Handler for when a touch input begins. */
    void TouchStarted(ETouchIndex::Type FingerIndex, FVector Location);

    protected:
    // APawn interface
    virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;
    // End of APawn interface
    };
    cpp
    // Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.

    #include "MyProject.h"
    #include "MyProjectCharacter.h"

    //////////////////////////////////////////////////////////////////////////
    // AMyProjectCharacter

    AMyProjectCharacter::AMyProjectCharacter(const class FPostConstructInitializeProperties& PCIP)
    : Super(PCIP)
    {

    // Set size for collision capsule
    CapsuleComponent->InitCapsuleSize(42.f, 96.0f);

    // set our turn rates for input
    BaseTurnRate = 45.f;
    BaseLookUpRate = 45.f;

    // Don't rotate when the controller rotates. Let that just affect the camera.
    bUseControllerRotationPitch = false;
    bUseControllerRotationYaw = false;
    bUseControllerRotationRoll = false;

    // Configure character movement
    CharacterMovement->bOrientRotationToMovement = true; // Character moves in the direction of input...
    CharacterMovement->RotationRate = FRotator(0.0f, 540.0f, 0.0f); // ...at this rotation rate
    CharacterMovement->JumpZVelocity = 600.f;
    CharacterMovement->AirControl = 0.2f;

    // Create a camera boom (pulls in towards the player if there is a collision)
    CameraBoom = PCIP.CreateDefaultSubobject<USpringArmComponent>(this, TEXT("CameraBoom"));
    CameraBoom->AttachTo(RootComponent);
    CameraBoom->TargetArmLength = Distance; // The camera follows at this distance behind the character
    CameraBoom->bUseControllerViewRotation = true; // Rotate the arm based on the controller

    // Create a follow camera
    FollowCamera = PCIP.CreateDefaultSubobject<UCameraComponent>(this, TEXT("FollowCamera"));
    FollowCamera->AttachTo(CameraBoom, USpringArmComponent::SocketName); // Attach the camera to the end of the boom and let the boom adjust to match the controller orientation
    FollowCamera->bUseControllerViewRotation = false; // Camera does not rotate relative to arm

    // Note: The skeletal mesh and anim blueprint references on the Mesh component (inherited from Character)
    // are set in the derived blueprint asset named MyCharacter (to avoid direct content references in C++)
    }

    //////////////////////////////////////////////////////////////////////////
    // Input

    void AMyProjectCharacter::SetupPlayerInputComponent(class UInputComponent* InputComponent)
    {
    // Set up gameplay key bindings
    check(InputComponent);
    InputComponent->BindAction("Jump", IE_Pressed, this, &ACharacter::Jump);
    InputComponent->BindAction("Switch_torp", IE_Pressed, this, &AMyProjectCharacter::Switch_torp);
    InputComponent->BindAxis("MoveForward", this, &AMyProjectCharacter::MoveForward);
    InputComponent->BindAxis("MoveRight", this, &AMyProjectCharacter::MoveRight);

    // We have 2 versions of the rotation bindings to handle different kinds of devices differently
    // "turn" handles devices that provide an absolute delta, such as a mouse.
    // "turnrate" is for devices that we choose to treat as a rate of change, such as an analog joystick
    InputComponent->BindAxis("Turn", this, &APawn::AddControllerYawInput);
    InputComponent->BindAxis("TurnRate", this, &AMyProjectCharacter::TurnAtRate);
    InputComponent->BindAxis("LookUp", this, &APawn::AddControllerPitchInput);
    InputComponent->BindAxis("LookUpRate", this, &AMyProjectCharacter::LookUpAtRate);

    // handle touch devices
    InputComponent->BindTouch(EInputEvent::IE_Pressed, this, &AMyProjectCharacter::TouchStarted);
    }


    void AMyProjectCharacter::TouchStarted(ETouchIndex::Type FingerIndex, FVector Location)
    {
    // jump, but only on the first touch
    if (FingerIndex == ETouchIndex::Touch1)
    {
    Jump();
    }
    }

    void AMyProjectCharacter::TurnAtRate(float Rate)
    {
    // calculate delta for this frame from the rate information
    AddControllerYawInput(Rate * BaseTurnRate * GetWorld()->GetDeltaSeconds());
    }

    void AMyProjectCharacter::LookUpAtRate(float Rate)
    {
    // calculate delta for this frame from the rate information
    AddControllerPitchInput(Rate * BaseLookUpRate * GetWorld()->GetDeltaSeconds());
    }

    void AMyProjectCharacter::MoveForward(float Value)
    {
    if ((Controller != NULL) && (Value != 0.0f))
    {
    // find out which way is forward
    const FRotator Rotation = Controller->GetControlRotation();
    const FRotator YawRotation(0, Rotation.Yaw, 0);

    // get forward vector
    const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
    AddMovementInput(Direction, Value);
    }
    }

    void AMyProjectCharacter::MoveRight(float Value)
    {
    if ( (Controller != NULL) && (Value != 0.0f) )
    {
    // find out which way is right
    const FRotator Rotation = Controller->GetControlRotation();
    const FRotator YawRotation(0, Rotation.Yaw, 0);

    // get right vector
    const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
    // add movement in that direction
    AddMovementInput(Direction, Value);
    }
    }
    void AMyProjectCharacter::Switch_torp(){
    if (TorP){
    TorP = false;
    Distance = 300.0f;
    }
    else{
    TorP = true;
    Distance = 0.0f;
    }
    }
    ini config file
    +AxisConfig=(AxisKeyName="Gamepad_LeftX",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
    +AxisConfig=(AxisKeyName="Gamepad_LeftY",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
    +AxisConfig=(AxisKeyName="Gamepad_RightX",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
    +AxisConfig=(AxisKeyName="Gamepad_RightY",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
    +AxisConfig=(AxisKeyName="MouseX",AxisProperties=(DeadZone=0.000000,Sensitivity=0.070000,Exponent=1.000000,bInvert=False))
    +AxisConfig=(AxisKeyName="MouseY",AxisProperties=(DeadZone=0.000000,Sensitivity=0.070000,Exponent=1.000000,bInvert=False))
    +AxisConfig=(AxisKeyName="Gamepad_LeftX",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
    +AxisConfig=(AxisKeyName="Gamepad_LeftY",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
    +AxisConfig=(AxisKeyName="Gamepad_RightX",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
    +AxisConfig=(AxisKeyName="Gamepad_RightY",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
    +AxisConfig=(AxisKeyName="MouseX",AxisProperties=(DeadZone=0.000000,Sensitivity=0.070000,Exponent=1.000000,bInvert=False))
    +AxisConfig=(AxisKeyName="MouseY",AxisProperties=(DeadZone=0.000000,Sensitivity=0.070000,Exponent=1.000000,bInvert=False))
    bUseMouseForTouch=False
    +ActionMappings=(ActionName="Jump",Key=SpaceBar,bShift=False,bCtrl=False,bAlt=False,bCmd=False)
    +ActionMappings=(ActionName="Switch_torp",Key=E,bShift=False,bCtrl=False,bAlt=False,bCmd=False)
    +AxisMappings=(AxisName="MoveForward",Key=W,Scale=1.000000)
    +AxisMappings=(AxisName="MoveForward",Key=S,Scale=-1.000000)
    +AxisMappings=(AxisName="MoveForward",Key=Up,Scale=1.000000)
    +AxisMappings=(AxisName="MoveForward",Key=Down,Scale=-1.000000)
    +AxisMappings=(AxisName="MoveForward",Key=Gamepad_LeftY,Scale=1.000000)
    +AxisMappings=(AxisName="MoveRight",Key=A,Scale=-1.000000)
    +AxisMappings=(AxisName="MoveRight",Key=D,Scale=1.000000)
    +AxisMappings=(AxisName="MoveRight",Key=Gamepad_LeftX,Scale=1.000000)
    +AxisMappings=(AxisName="TurnRate",Key=Gamepad_RightX,Scale=1.000000)
    +AxisMappings=(AxisName="TurnRate",Key=Left,Scale=-1.000000)
    +AxisMappings=(AxisName="TurnRate",Key=Right,Scale=1.000000)
    +AxisMappings=(AxisName="Turn",Key=MouseX,Scale=1.000000)
    +AxisMappings=(AxisName="LookUpRate",Key=Gamepad_RightY,Scale=1.000000)
    +AxisMappings=(AxisName="LookUp",Key=MouseY,Scale=-1.000000)
    Can you do me a favor and put code tags on this please? Then i'll take another look.

    Leave a comment:


  • replied
    The function isn't called,this is the full source code:
    header
    // Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
    #pragma once
    #include "GameFramework/Character.h"
    #include "MyProjectCharacter.generated.h"

    UCLASS(config=Game)
    class AMyProjectCharacter : public ACharacter
    {
    GENERATED_UCLASS_BODY()

    //Camera controll bool
    UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = Camera)
    bool TorP;

    //Camera distance variable
    UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = Camera)
    float Distance;

    /** Camera boom positioning the camera behind the character */
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Camera)
    TSubobjectPtr<class USpringArmComponent> CameraBoom;

    /** Follow camera */
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Camera)
    TSubobjectPtr<class UCameraComponent> FollowCamera;

    /** Base turn rate, in deg/sec. Other scaling may affect final turn rate. */
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Camera)
    float BaseTurnRate;

    /** Base look up/down rate, in deg/sec. Other scaling may affect final rate. */
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Camera)
    float BaseLookUpRate;

    protected:

    //Switch T/P
    void Switch_torp();

    /** Called for forwards/backward input */
    void MoveForward(float Value);

    /** Called for side to side input */
    void MoveRight(float Value);

    /**
    * Called via input to turn at a given rate.
    * @param Rate This is a normalized rate, i.e. 1.0 means 100% of desired turn rate
    */
    void TurnAtRate(float Rate);

    /**
    * Called via input to turn look up/down at a given rate.
    * @param Rate This is a normalized rate, i.e. 1.0 means 100% of desired turn rate
    */
    void LookUpAtRate(float Rate);

    /** Handler for when a touch input begins. */
    void TouchStarted(ETouchIndex::Type FingerIndex, FVector Location);

    protected:
    // APawn interface
    virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;
    // End of APawn interface
    };
    cpp
    // Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.

    #include "MyProject.h"
    #include "MyProjectCharacter.h"

    //////////////////////////////////////////////////////////////////////////
    // AMyProjectCharacter

    AMyProjectCharacter::AMyProjectCharacter(const class FPostConstructInitializeProperties& PCIP)
    : Super(PCIP)
    {

    // Set size for collision capsule
    CapsuleComponent->InitCapsuleSize(42.f, 96.0f);

    // set our turn rates for input
    BaseTurnRate = 45.f;
    BaseLookUpRate = 45.f;

    // Don't rotate when the controller rotates. Let that just affect the camera.
    bUseControllerRotationPitch = false;
    bUseControllerRotationYaw = false;
    bUseControllerRotationRoll = false;

    // Configure character movement
    CharacterMovement->bOrientRotationToMovement = true; // Character moves in the direction of input...
    CharacterMovement->RotationRate = FRotator(0.0f, 540.0f, 0.0f); // ...at this rotation rate
    CharacterMovement->JumpZVelocity = 600.f;
    CharacterMovement->AirControl = 0.2f;

    // Create a camera boom (pulls in towards the player if there is a collision)
    CameraBoom = PCIP.CreateDefaultSubobject<USpringArmComponent>(this, TEXT("CameraBoom"));
    CameraBoom->AttachTo(RootComponent);
    CameraBoom->TargetArmLength = Distance; // The camera follows at this distance behind the character
    CameraBoom->bUseControllerViewRotation = true; // Rotate the arm based on the controller

    // Create a follow camera
    FollowCamera = PCIP.CreateDefaultSubobject<UCameraComponent>(this, TEXT("FollowCamera"));
    FollowCamera->AttachTo(CameraBoom, USpringArmComponent::SocketName); // Attach the camera to the end of the boom and let the boom adjust to match the controller orientation
    FollowCamera->bUseControllerViewRotation = false; // Camera does not rotate relative to arm

    // Note: The skeletal mesh and anim blueprint references on the Mesh component (inherited from Character)
    // are set in the derived blueprint asset named MyCharacter (to avoid direct content references in C++)
    }

    //////////////////////////////////////////////////////////////////////////
    // Input

    void AMyProjectCharacter::SetupPlayerInputComponent(class UInputComponent* InputComponent)
    {
    // Set up gameplay key bindings
    check(InputComponent);
    InputComponent->BindAction("Jump", IE_Pressed, this, &ACharacter::Jump);
    InputComponent->BindAction("Switch_torp", IE_Pressed, this, &AMyProjectCharacter::Switch_torp);
    InputComponent->BindAxis("MoveForward", this, &AMyProjectCharacter::MoveForward);
    InputComponent->BindAxis("MoveRight", this, &AMyProjectCharacter::MoveRight);

    // We have 2 versions of the rotation bindings to handle different kinds of devices differently
    // "turn" handles devices that provide an absolute delta, such as a mouse.
    // "turnrate" is for devices that we choose to treat as a rate of change, such as an analog joystick
    InputComponent->BindAxis("Turn", this, &APawn::AddControllerYawInput);
    InputComponent->BindAxis("TurnRate", this, &AMyProjectCharacter::TurnAtRate);
    InputComponent->BindAxis("LookUp", this, &APawn::AddControllerPitchInput);
    InputComponent->BindAxis("LookUpRate", this, &AMyProjectCharacter::LookUpAtRate);

    // handle touch devices
    InputComponent->BindTouch(EInputEvent::IE_Pressed, this, &AMyProjectCharacter::TouchStarted);
    }


    void AMyProjectCharacter::TouchStarted(ETouchIndex::Type FingerIndex, FVector Location)
    {
    // jump, but only on the first touch
    if (FingerIndex == ETouchIndex::Touch1)
    {
    Jump();
    }
    }

    void AMyProjectCharacter::TurnAtRate(float Rate)
    {
    // calculate delta for this frame from the rate information
    AddControllerYawInput(Rate * BaseTurnRate * GetWorld()->GetDeltaSeconds());
    }

    void AMyProjectCharacter::LookUpAtRate(float Rate)
    {
    // calculate delta for this frame from the rate information
    AddControllerPitchInput(Rate * BaseLookUpRate * GetWorld()->GetDeltaSeconds());
    }

    void AMyProjectCharacter::MoveForward(float Value)
    {
    if ((Controller != NULL) && (Value != 0.0f))
    {
    // find out which way is forward
    const FRotator Rotation = Controller->GetControlRotation();
    const FRotator YawRotation(0, Rotation.Yaw, 0);

    // get forward vector
    const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
    AddMovementInput(Direction, Value);
    }
    }

    void AMyProjectCharacter::MoveRight(float Value)
    {
    if ( (Controller != NULL) && (Value != 0.0f) )
    {
    // find out which way is right
    const FRotator Rotation = Controller->GetControlRotation();
    const FRotator YawRotation(0, Rotation.Yaw, 0);

    // get right vector
    const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
    // add movement in that direction
    AddMovementInput(Direction, Value);
    }
    }
    void AMyProjectCharacter::Switch_torp(){
    if (TorP){
    TorP = false;
    Distance = 300.0f;
    }
    else{
    TorP = true;
    Distance = 0.0f;
    }
    }
    ini config file
    +AxisConfig=(AxisKeyName="Gamepad_LeftX",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
    +AxisConfig=(AxisKeyName="Gamepad_LeftY",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
    +AxisConfig=(AxisKeyName="Gamepad_RightX",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
    +AxisConfig=(AxisKeyName="Gamepad_RightY",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
    +AxisConfig=(AxisKeyName="MouseX",AxisProperties=(DeadZone=0.000000,Sensitivity=0.070000,Exponent=1.000000,bInvert=False))
    +AxisConfig=(AxisKeyName="MouseY",AxisProperties=(DeadZone=0.000000,Sensitivity=0.070000,Exponent=1.000000,bInvert=False))
    +AxisConfig=(AxisKeyName="Gamepad_LeftX",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
    +AxisConfig=(AxisKeyName="Gamepad_LeftY",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
    +AxisConfig=(AxisKeyName="Gamepad_RightX",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
    +AxisConfig=(AxisKeyName="Gamepad_RightY",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
    +AxisConfig=(AxisKeyName="MouseX",AxisProperties=(DeadZone=0.000000,Sensitivity=0.070000,Exponent=1.000000,bInvert=False))
    +AxisConfig=(AxisKeyName="MouseY",AxisProperties=(DeadZone=0.000000,Sensitivity=0.070000,Exponent=1.000000,bInvert=False))
    bUseMouseForTouch=False
    +ActionMappings=(ActionName="Jump",Key=SpaceBar,bShift=False,bCtrl=False,bAlt=False,bCmd=False)
    +ActionMappings=(ActionName="Switch_torp",Key=E,bShift=False,bCtrl=False,bAlt=False,bCmd=False)
    +AxisMappings=(AxisName="MoveForward",Key=W,Scale=1.000000)
    +AxisMappings=(AxisName="MoveForward",Key=S,Scale=-1.000000)
    +AxisMappings=(AxisName="MoveForward",Key=Up,Scale=1.000000)
    +AxisMappings=(AxisName="MoveForward",Key=Down,Scale=-1.000000)
    +AxisMappings=(AxisName="MoveForward",Key=Gamepad_LeftY,Scale=1.000000)
    +AxisMappings=(AxisName="MoveRight",Key=A,Scale=-1.000000)
    +AxisMappings=(AxisName="MoveRight",Key=D,Scale=1.000000)
    +AxisMappings=(AxisName="MoveRight",Key=Gamepad_LeftX,Scale=1.000000)
    +AxisMappings=(AxisName="TurnRate",Key=Gamepad_RightX,Scale=1.000000)
    +AxisMappings=(AxisName="TurnRate",Key=Left,Scale=-1.000000)
    +AxisMappings=(AxisName="TurnRate",Key=Right,Scale=1.000000)
    +AxisMappings=(AxisName="Turn",Key=MouseX,Scale=1.000000)
    +AxisMappings=(AxisName="LookUpRate",Key=Gamepad_RightY,Scale=1.000000)
    +AxisMappings=(AxisName="LookUp",Key=MouseY,Scale=-1.000000)

    Leave a comment:


  • replied
    You might want to double check the actual binding in the config(Within' the editor) or put some debug messages in these functions to see if they're actually being called or not.

    Leave a comment:


  • started a topic Problem whit keybinding

    Problem whit keybinding

    Keybinding:
    InputComponent->BindAction("SwitchTF", IE_Pressed, this, &AOldSchoolArenaFPSCharacter::Istorp);
    Isrorp function:
    void AOldSchoolArenaFPSCharacter::Istorp()
    {
    if (bIsTP)
    {
    bIsTP = false;
    Distance = 300.0f;
    }
    else
    {
    bIsTP = true;
    Distance = 0.0f;
    }
    }
    Where is the error?When i press H nothing appen.All the code I posted is in the same class end setting on editor are:
    ActionMappings
    ...
    SwitchTF
    H
Working...
X