Add jump to pedestrian control

This commit is contained in:
nsubiron 2019-01-17 14:40:18 +01:00
parent 4ab822bcce
commit 4c68cdb345
5 changed files with 38 additions and 14 deletions

View File

@ -22,37 +22,44 @@ namespace rpc {
WalkerControl(
geom::Vector3D in_direction,
float in_speed)
float in_speed,
bool in_jump)
: direction(in_direction),
speed(in_speed) {}
speed(in_speed),
jump(in_jump) {}
geom::Vector3D direction = {1.0f, 0.0f, 0.0f};
float speed = 0.0f;
bool jump = false;
#ifdef LIBCARLA_INCLUDED_FROM_UE4
WalkerControl(const FWalkerControl &Control)
: direction(Control.Direction.X, Control.Direction.Y, Control.Direction.Z),
speed(1e-2f * Control.Speed) {}
speed(1e-2f * Control.Speed),
jump(Control.Jump) {}
operator FWalkerControl() const {
FWalkerControl Control;
Control.Direction = {direction.x, direction.y, direction.z};
Control.Speed = 1e2f * speed;
Control.Jump = jump;
return Control;
}
#endif // LIBCARLA_INCLUDED_FROM_UE4
bool operator!=(const WalkerControl &rhs) const {
return direction != rhs.direction || speed != rhs.speed;
return direction != rhs.direction || speed != rhs.speed || jump != rhs.jump;
}
bool operator==(const WalkerControl &rhs) const {
return !(*this != rhs);
}
MSGPACK_DEFINE_ARRAY(direction, speed);
MSGPACK_DEFINE_ARRAY(direction, speed, jump);
};
} // namespace rpc

View File

@ -60,16 +60,18 @@ namespace detail {
PackedWalkerControl(const rpc::WalkerControl &control)
: direction{control.direction.x, control.direction.y, control.direction.z},
speed(control.speed) {}
speed(control.speed),
jump(control.jump) {}
operator rpc::WalkerControl() const {
return {geom::Vector3D{direction[0u], direction[1u], direction[2u]}, speed};
return {geom::Vector3D{direction[0u], direction[1u], direction[2u]}, speed, jump};
}
private:
float direction[3u];
float speed;
bool jump;
};
#pragma pack(pop)

View File

@ -12,8 +12,11 @@
namespace carla {
namespace rpc {
static auto boolalpha(bool b) {
return b ? "True" : "False";
};
std::ostream &operator<<(std::ostream &out, const VehicleControl &control) {
auto boolalpha = [](bool b) { return b ? "True" : "False"; };
out << "VehicleControl(throttle=" << control.throttle
<< ", steer=" << control.steer
<< ", brake=" << control.brake
@ -26,7 +29,8 @@ namespace rpc {
std::ostream &operator<<(std::ostream &out, const WalkerControl &control) {
out << "WalkerControl(direction=" << control.direction
<< ", speed=" << control.speed << ')';
<< ", speed=" << control.speed
<< ", jump=" << boolalpha(control.jump) << ')';
return out;
}
@ -60,11 +64,13 @@ void export_control() {
;
class_<cr::WalkerControl>("WalkerControl")
.def(init<cg::Vector3D, float>(
.def(init<cg::Vector3D, float, bool>(
(arg("direction")=cg::Vector3D{1.0f, 0.0f, 0.0f},
arg("speed")=0.0f)))
arg("speed")=0.0f,
arg("jump")=false)))
.def_readwrite("direction", &cr::WalkerControl::direction)
.def_readwrite("speed", &cr::WalkerControl::speed)
.def_readwrite("jump", &cr::WalkerControl::jump)
.def("__eq__", &cr::WalkerControl::operator==)
.def("__ne__", &cr::WalkerControl::operator!=)
.def(self_ns::str(self_ns::self))

View File

@ -18,4 +18,7 @@ struct CARLA_API FWalkerControl
UPROPERTY(Category = "Walker Control", EditAnywhere, BlueprintReadWrite)
float Speed = 0.0f;
UPROPERTY(Category = "Walker Control", EditAnywhere, BlueprintReadWrite)
bool Jump = false;
};

View File

@ -35,16 +35,22 @@ void AWalkerController::Possess(APawn *InPawn)
}
MovementComponent->MaxWalkSpeed = GetMaximumWalkSpeed();
MovementComponent->JumpZVelocity = 500.0f;
Character->JumpMaxCount = 2;
}
void AWalkerController::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
auto *Pawn = GetPawn();
auto *Character = GetCharacter();
if (Pawn != nullptr)
if (Character != nullptr)
{
Pawn->AddMovementInput(Control.Direction, Control.Speed / GetMaximumWalkSpeed());
Character->AddMovementInput(Control.Direction, Control.Speed / GetMaximumWalkSpeed());
if (Control.Jump)
{
Character->Jump();
}
}
}