Download

How to edit ComponentVelocity of an Actor?

Hello guys, I’m making my own vehicle handling because I DON’T want to use default components, I repeat I’m making my own handling.
Currently I have setup a pawn that has a custom ActorComponent called VehicleHandling, this is the handling manager, what I am doing in a method called ApplyThrottle is simply getting the longitudinal froce by summing Traction force, Drag force and Rolling Resistance Force, this is the code (VehicleHandling.cpp):



void UVehicleHandling::ApplyThrottle(float DeltaTime)
{
FVector CurrentVelocity = VehicleMesh->ComponentVelocity;

float EngineForce = 252.0f;
FVector Ftraction = FVector(Throttle * EngineForce, 0.0f, 0.0f);

float Cdrag = 0.29f;
FVector Fdrag = -Cdrag * CurrentVelocity * CurrentVelocity.Size();

float Crr = 0.01f;
FVector Frr = -Crr * CurrentVelocity;

FVector Flong = Ftraction + Fdrag + Frr;
VehicleMesh->ComponentVelocity = FVector(25.0f, 100.0f, 100.0f);
}


As you can see I’m using the ComponentVelocity, the VehicleMesh is just


Cast<UStaticMeshComponent>(GetOwner()->GetDefaultSubobjectByName(TEXT("VehicleMesh")));

VehicleMesh is the base mesh inside the pawn component.
I tried using Get/SetPhysicsLinearVelocity() but using the Fdrag result in the car to wrap in the void and go out of memory. I’ve read about using a MovementComponent, but I cannot find ANY tutorial regarding a basic MovementComponent, just PawnMovementComponent and CharacterMovementComponent.
I don’t want to use PawnMovementComponent because the VehicleHandling class will be used for every vehicle there AND npc will be Actors and not Pawns.
What should I do? The UE4 documentation is not helping at all.