diff --git a/Unreal/Plugins/AirSim/Source/ManualPoseController.cpp b/Unreal/Plugins/AirSim/Source/ManualPoseController.cpp index a4ead26332..87cf0bacd0 100644 --- a/Unreal/Plugins/AirSim/Source/ManualPoseController.cpp +++ b/Unreal/Plugins/AirSim/Source/ManualPoseController.cpp @@ -18,7 +18,8 @@ void UManualPoseController::initializeForPlay() right_roll_mapping_ = FInputAxisKeyMapping("inputManualRightRoll", EKeys::E); up_pitch_mapping_ = FInputAxisKeyMapping("inputManualUpPitch", EKeys::W); down_pitch_mapping_ = FInputAxisKeyMapping("inputManualDownPitch", EKeys::S); - + inc_speed_mapping_ = FInputAxisKeyMapping("inputManualSpeedIncrease", EKeys::LeftShift); + dec_speed_mapping_ = FInputAxisKeyMapping("inputManualSpeedDecrease", EKeys::LeftControl); input_positive_ = inpute_negative_ = last_velocity_ = FVector::ZeroVector; } @@ -27,6 +28,7 @@ void UManualPoseController::clearBindings() left_binding_ = right_binding_ = up_binding_ = down_binding_ = nullptr; forward_binding_ = backward_binding_ = left_yaw_binding_ = up_pitch_binding_ = nullptr; right_yaw_binding_ = down_pitch_binding_ = left_roll_binding_ = right_roll_binding_ = nullptr; + inc_speed_binding_ = dec_speed_binding_ = nullptr; } void UManualPoseController::setActor(AActor* actor) @@ -102,6 +104,10 @@ void UManualPoseController::removeInputBindings() UAirBlueprintLib::RemoveAxisBinding(up_pitch_mapping_, up_pitch_binding_, actor_); if (down_pitch_binding_) UAirBlueprintLib::RemoveAxisBinding(down_pitch_mapping_, down_pitch_binding_, actor_); + if (inc_speed_binding_) + UAirBlueprintLib::RemoveAxisBinding(inc_speed_mapping_, inc_speed_binding_, actor_); + if (dec_speed_binding_) + UAirBlueprintLib::RemoveAxisBinding(dec_speed_mapping_, dec_speed_binding_, actor_); clearBindings(); } @@ -122,6 +128,8 @@ void UManualPoseController::setupInputBindings() right_roll_binding_ = &UAirBlueprintLib::BindAxisToKey(right_roll_mapping_, actor_, this, &UManualPoseController::inputManualRightRoll); up_pitch_binding_ = &UAirBlueprintLib::BindAxisToKey(up_pitch_mapping_, actor_, this, &UManualPoseController::inputManualUpPitch); down_pitch_binding_ = &UAirBlueprintLib::BindAxisToKey(down_pitch_mapping_, actor_, this, &UManualPoseController::inputManualDownPitch); + inc_speed_binding_ = &UAirBlueprintLib::BindAxisToKey(inc_speed_mapping_, actor_, this, &UManualPoseController::inputManualSpeedIncrease); + dec_speed_binding_ = &UAirBlueprintLib::BindAxisToKey(dec_speed_mapping_, actor_, this, &UManualPoseController::inputManualSpeedDecrease); } void UManualPoseController::updateDeltaPosition(float dt) @@ -129,7 +137,7 @@ void UManualPoseController::updateDeltaPosition(float dt) FVector input = input_positive_ - inpute_negative_; if (!FMath::IsNearlyZero(input.SizeSquared())) { if (FMath::IsNearlyZero(acceleration_)) - last_velocity_ = input * 1000; + last_velocity_ = input * speed_scaler_; else last_velocity_ += input * (acceleration_ * dt); delta_position_ += actor_->GetActorRotation().RotateVector(last_velocity_ * dt); @@ -139,6 +147,20 @@ void UManualPoseController::updateDeltaPosition(float dt) } } +void UManualPoseController::inputManualSpeedIncrease(float val) +{ + if (!FMath::IsNearlyEqual(val, 0.f)) + speed_scaler_ += val * 20; +} +void UManualPoseController::inputManualSpeedDecrease(float val) +{ + if (!FMath::IsNearlyEqual(val, 0.f)) + speed_scaler_ -= val * 20; + + if (speed_scaler_ <= 0.0) + speed_scaler_ = 20.0; +} + void UManualPoseController::inputManualLeft(float val) { inpute_negative_.Y = val; diff --git a/Unreal/Plugins/AirSim/Source/ManualPoseController.h b/Unreal/Plugins/AirSim/Source/ManualPoseController.h index e4e2d39c4f..5a4b5aa85a 100644 --- a/Unreal/Plugins/AirSim/Source/ManualPoseController.h +++ b/Unreal/Plugins/AirSim/Source/ManualPoseController.h @@ -33,6 +33,8 @@ class AIRSIM_API UManualPoseController : public UObject void inputManualRightRoll(float val); void inputManualUpPitch(float val); void inputManualDownPitch(float val); + void inputManualSpeedIncrease(float val); + void inputManualSpeedDecrease(float val); void setupInputBindings(); void removeInputBindings(); @@ -42,17 +44,19 @@ class AIRSIM_API UManualPoseController : public UObject FInputAxisBinding *left_binding_, *right_binding_, *up_binding_, *down_binding_; FInputAxisBinding *forward_binding_, *backward_binding_, *left_yaw_binding_, *right_yaw_binding_; FInputAxisBinding *up_pitch_binding_, *down_pitch_binding_, *left_roll_binding_, *right_roll_binding_; + FInputAxisBinding *inc_speed_binding_, *dec_speed_binding_; FInputAxisKeyMapping left_mapping_, right_mapping_, up_mapping_, down_mapping_; FInputAxisKeyMapping forward_mapping_, backward_mapping_, left_yaw_mapping_, right_yaw_mapping_; FInputAxisKeyMapping up_pitch_mapping_, down_pitch_mapping_, left_roll_mapping_, right_roll_mapping_; + FInputAxisKeyMapping inc_speed_mapping_, dec_speed_mapping_; FVector delta_position_; FRotator delta_rotation_; AActor* actor_; - float acceleration_ = 0; + float acceleration_ = 0, speed_scaler_ = 1000; FVector input_positive_, inpute_negative_; FVector last_velocity_; }; \ No newline at end of file