4.7.5 Issue with SetPhysicsLinearVelocity

Hi,

Yesterday i updated from 4.7.4 to 4.7.5 and SetPhysicsLinearVelocity seems to cause a lot of jerking. I have a helicopter using SetPhysicsLinearVelocity() function and in 4.7.4 everything was good. Now in 4.7.5 the helicopter jerks a lot. Below is the code i am using to apply thrust:

void AHelicopter::ApplyThrust()
{
	const FVector UpVec = FloorCollider->GetUpVector();
	const FRotator ForwardVectorRotator = FRotator( 0.f, GetActorRotation().Yaw, 0.f );
	const FVector ForwardVector = FRotationMatrix( ForwardVectorRotator ).GetScaledAxis( EAxis::X );
	const FVector UpVecMultplied = UpVec * MaxUpwardThrust;
	const FVector ForwardVectorMultiplied = ForwardVector * ((GetActorRotation().Pitch * ForwardThrust) * -1);
	const FVector NewVelocity = UpVecMultplied + ForwardVectorMultiplied;
	FloorCollider->SetPhysicsLinearVelocity( NewVelocity );
}

FloorCollider is a box component (used as Root component also). Everytime i apply thrust my vehicle randomly jerks.

Hey -

I’m investigating your issue and want to make sure I’m using the same setup that you are. I created an actor class and added a box component to it. I then created a function and copied the code you provided into it. However I receive compile issues because “MaxUpwardThrust” and “ForwrdThrust” are undefined. Can you let me know what the value of these variables are or how they’re calculated?

Cheers

Hi ,

I set the value of MaxUpdwardThrust like this:

if (scale != 0.f)
			{
				MaxUpwardThrust = FMath::FInterpTo( MainUpwardThrust, (scale * ThrustPower), UGameplayStatics::GetWorldDeltaSeconds( GetWorld() ), 8.f);
			}
			else
			{
				MaxUpwardThrust = FMath::FInterpTo( MainUpwardThrust, HoverPower, UGameplayStatics::GetWorldDeltaSeconds( GetWorld() ), 2.f);
			}
			ApplyThrust();

I used the above code in an input function (MoveForward for example).

ThrustPower = 1.f;

ForwardThrust = 110.f;

It appears that scale and HoverPower are also unidentified types/values in the above code. Would it be possible to post the class where these functions are being used?

Scale is the Axis value of input event.

HoverPower = -10.f;

I’d love to post the class but its huge.

You should be able to zip both the header and source file and submit here as an attachment. If there is sensitive information you can instead upload them to dropbox and then send me a private message on the forums with a link to the dropbox.

Hey -

I just wanted to check if you have had the chance to upload the code files to dropbox so that I can use them as reference in reproducing this bug. For the time being I am marking this as resolved for tracking purposes. Let me know if you were able to find a solution for your problem or if this is something you’re still being affected by.

Cheers

Hi ,

Im really sorry for this delayed response. I will PM you the dropbox link. May i know your username on the forums?

You can find me on the forums as

Thanks . PM sent.

Hey -

I created a quick setup to test SetPhysicsLinearVelocity(). I started by defining a static mesh component as part of an Actor based class:

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Test)
	UStaticMeshComponent* MeshTest;

and then set it up in the constructor:

MeshTest = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MeshTest"));
	MeshTest->SetSimulatePhysics(true);
	RootComponent = MeshTest;

In the tick function I used the SetPhysicsLinearVelocity to move the static mesh upward

MeshTest->SetPhysicsLinearVelocity(FVector(0, 0, 20));

In the editor when I create a blueprint of this class and set a static mesh to the component I can watch it move upward slowly and smoothly while playing. I used a static mesh since it would have something I could see the effect of. If you’re using a Box Component then I would assume that the box component is reacting to the function call, but I’m not sure how the box component interacts with your helicopter.