Hi forum 
I am somewhat new to unreal and am trying to get the physics linear velocity of my chaos modular vehicle pawn in order to do stuff with it (eg speedometer, control level of music etc)
I am doing this through using the get physics linear velocity on event tick. But even with this simple example of just printing the returned linear velocity, there are multiple ticks where it is 0 and only intermittent ticks where it is accurate.
I was wondering what the reason for this would be? Are there alternative ways anyone would suggest to get the current speed of the vehicle.
Speed and Velocity are different jargons and concept for how fast an object is moving.
Velocity : is Vectoral, have direction.
Speed : is Scalar , have no direction.
So if you want to make a speedOmeter, on the node of “GetPhsyicsLinearVelocity”-> VectorLength
will provide somewhat a true value of the car movement.
In addition those minor changes can come from phsyics simulation of car already, even though there is no movement input.
Thanks for your reply. I should have prefaced that this is a simplified example, I’ve got extra bits to calculate the magnitude of the vector for speed not shown here.
My issue is that if I get the value each tick, there are multiple ticks where it just returns zero even if in motion, and some ticks that return the actual velocity.
Oh sory then, I just assumed maybe its a simple thing.
I found this maybe its relative velocity
FVector UPrimitiveComponent::GetPhysicsLinearVelocity(FName BoneName)
{
if (FBodyInstance* BI = GetBodyInstance(BoneName))
{
return BI->GetUnrealWorldVelocity();
}
else if (Chaos::FConstPhysicsObjectHandle Handle = GetPhysicsObjectByName(BoneName))
{
FLockedReadPhysicsObjectExternalInterface Interface = FPhysicsObjectExternalInterface::LockRead(Handle);
return Interface->GetV(Handle);
}
return FVector(0,0,0);
}
and this goes to in chaos vehicle to seems
FVector FReadPhysicsObjectInterface<Id>::GetV(const FConstPhysicsObjectHandle Object)
{
if (!Object)
{
return FVector::Zero();
}
if (TThreadParticle<Id>* Particle = Object->GetParticle<Id>())
{
if (Chaos::TThreadRigidParticle<Id>* Rigid = Particle->CastToRigidParticle())
{
return Rigid->GetV();
}
}
return FVector::Zero();
}
and seems this is on thread context sometimes if everything is right can return zero for chaos seems. Could be sleeping or not updated also as a guess only. Can you check the object state at that ticks?
I am also learning deeper about chaos so wanted to check.
1 Like
Heya! Thanks again, this really helped.
I wasn’t sure exactly how to get the state of my object. But with you mentioning the object could be sleeping, I found a ‘is any rigid bodies awake’ function that I was able to use to make sure my object was awake when getting the linear velocity.
This seemed to work for me.
Cheers!
1 Like