UE4 SetPhysicsLinearVelocity、AddForce区别
SetPhysicsAngularVelocity:用于旋转物体。但官方文档建议谨慎使用此接口,建议用 AddTorque或者AddImpulse
AddForce用法:
- mesh->AddForce(FVector::RightVector * mesh->GetBodyInstance()->GetBodyMass() * 1000);
https://answers.unrealengine.com/questions/290824/addforceaddimpulse-wont-work.html
修改Velocity:
一般动画蓝图中使用Velocity来判定当前对象的移动速度从而来判定是否播放跑步动画。AddForce并不会修改Velocity值,所以如果要移动的同时来设置Velocity,需要手动设置:
- MyChar->GetCharacterMovement()->Velocity += FVector(0,0,20000);
https://answers.unrealengine.com/questions/27069/addimpulse-or-addforce-on-character.html
注意,如果要使用SetPhysicsLinearVelocity(),需要将SetSimulatePhysics设置为true:
- MyCharacter->GetMesh()->SetSimulatePhysics(true);
- MyCharacter->GetMesh()->SetPhysicsLinearVelocity(FVector(100.f, 100.f, 100.f));
https://answers.unrealengine.com/questions/140978/how-to-set-a-initial-velocity.html
UPrimitiveComponent::AddForce
https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Components/UPrimitiveComponent/AddForce/index.html
UPrimitiveComponent::AddImpulse
https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Components/UPrimitiveComponent/AddImpulse/index.html
UPrimitiveComponent::SetPhysicsLinearVelocity
https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Components/UPrimitiveComponent/SetPhysicsLinearVelocity/index.html
UPrimitiveComponent::SetPhysicsAngularVelocity
https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Components/UPrimitiveComponent/SetPhysicsAngularVelocity/index.html
全部评论:0条