Hey Y’all, Im trying to make a flappy bird game, and I want to clamp the players X axis, however, whenever i try to do so, i get this error:
no suitable constructor exists to convert from “double” to “UE::Math::TVector”
Here is the code for the tick function,
void AFlappyCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if(IsValid(FlappyBirdREF))
{
FlappyBirdREF->AddForce(FVector(-700.0f, 0.0f, 0.0f), NAME_None, true);
float MyMaximumSpeedValue = 1000.0f;
CurrentVelocity = FlappyBirdREF->GetPhysicsLinearVelocity();
FVector CurrentVelocityX = CurrentVelocity.X;
FVector clampedVelocity = CurrentVelocity.GetClampedToMaxSize(MyMaximumSpeedValue);
FlappyBirdREF->SetPhysicsLinearVelocity(clampedVelocity.XAxisVector, true);
}
}
jwatte
(jwatte)
October 9, 2023, 5:08pm
2
CurrentVelocity.X is a double (just the value of the X coordinate.)
You might do something like:
FVector CurrentVelocityX(CurrentVelocity.X, 0, 0);
void AFlappyCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if(IsValid(FlappyBirdREF))
{
FlappyBirdREF->AddForce(FVector(700.0f, 0.0f, 0.0f), NAME_None, true);
float MyMaximumSpeedValue = 1000.0f;
CurrentVelocity = FlappyBirdREF->GetPhysicsLinearVelocity();
FVector CurrentVelocityX(CurrentVelocity.X, 0.0f, 0.0f);
FVector clampedVelocityX = CurrentVelocityX.GetClampedToMaxSize(MyMaximumSpeedValue);
FlappyBirdREF->SetPhysicsLinearVelocity(clampedVelocityX, true);
}
}
The Bird now accelarates extremly fast, completly ignoring the clampedvelocity, why is this happening?
system
(system)
Closed
November 8, 2023, 5:17pm
6
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.