I’m tryin to change the gravity direction and so far I managed to do that but I can’t change it in real time during the game. So far I have the following code in my game class:
void ABallScrollBall::SetupPlayerInputComponent(class UInputComponent* InputComponent) {
// some stuff
InputComponent->BindAction("GravityRight", IE_Pressed, this, &ABallScrollBall::GravityRight);
InputComponent->BindAction("GravityLeft", IE_Pressed, this, &ABallScrollBall::GravityLeft);
InputComponent->BindAction("GravityUp", IE_Pressed, this, &ABallScrollBall::GravityUp);
InputComponent->BindAction("GravityDown", IE_Pressed, this, &ABallScrollBall::GravityDown);
}
void ABallScrollBall::GravityRight() {
//call ChGrav(1);
}
void ABallScrollBall::GravityLeft() {
//call ChGrav(2);
}
void ABallScrollBall::GravityUp() {
//call ChGrav(3);
}
void ABallScrollBall::GravityDown() {
//call ChGrav(4);
}
In the PhysLevel.cpp:
void UWorld::SetupPhysicsTickFunctions(float DeltaSeconds)
{
// stuff
//FVector DefaultGravity( 0.f, 0.f, GetGravityZ() ); was the default
//stuff
}
void UWorld::ChGrav(short dir) {
switch (dir) {
case 1:
DefaultGravity = FVector(0.f, -500.f, 0.f);
break;
case 2:
DefaultGravity = FVector(0.f, 500.f, 0.f);
break;
case 3:
DefaultGravity = FVector(0.f, 0.f, 500.f);
break;
default:
DefaultGravity = FVector(0.f, 0.f, -500.f);
}
}
And in the World.h
//stuff
public:
FVector DefaultGravity;
void ChGrav(short dir);
//stuff
(i think) The problem is that I can’t access the UWorld class.