Ok, you have a couple of options for what you want to do.
You can manage input on PlayerController (The class that control your car class). On playerController you can intercep input “earlier”, to do more stuff.
You can manage input on car directly.
Based on what you asked, i’m gonna go with the second choice, manage input directly on vehicule, but you have multiples options.
Option 1 input in car directly
You need to ovveride function to handle input on your car directly
header file
virtual void SetupPlayerInputComponent(UInputComponent* InputComponent) override;
Choice 1
Source file
void AVehiculeMobilePawn::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
// set up gameplay key bindings
check(InputComponent);
if(FPlatformMisc::GetUseVirtualJoysticks() || GetDefault<UInputSettings>()->bUseMouseForTouch )
{
InputComponent->BindTouch(EInputEvent::IE_Pressed, this, &&AVehiculeMobilePawn::BeginTouch);
InputComponent->BindTouch(EInputEvent::IE_Released, this, &&AVehiculeMobilePawn::EndTouch);
}
}
After you create these two functions on your car, Begin and End. In these functions you can use the code you written on your first post.
Choice 2 (I’m based on c++ Vehicule template aimed for mobile)
Source file
void AVehiculeMobilePawn::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
// set up gameplay key bindings
check(InputComponent);
InputComponent->BindAxis("MoveForward", this, &AVehiculeMobilePawn::MoveForward);
InputComponent->BindAxis("MoveRight", this, &AVehiculeMobilePawn::MoveRight);
/*More binds ....*/
}
You Create your 2 functions moveForward (not required in example) MoveRight. In the moveRight you can use your code as above.
If you follow option 2 you’ll need to define these fuctions in projects setting input.
Compile and lauch your game. In Unreal Engine, you go Edit–>Project Settings–> Engine section on left–>Input.
It will be axis mappings you can refer at this if you want to : Input doc and axis and actions mapping for more details
Option 2 input on PlayerController
If you want to intercept input earlier and have more controls you can manage input on you PlayerController.
PlayerController.h
virtual bool InputTouch(uint32 Handle, ETouchType::Type Type, const FVector2D& TouchLocation, FDateTime DeviceTimestamp, uint32 TouchpadIndex);
Look more similar to what you have.
If need more details on that option, just tell me i’m gonna explain too.
If you have any problems or questions don’t hesitate to ask, i’m glad to help.
gamer08