Several methods UE4 moving object

Transfer: https://dawnarc.com/2016/06/ue4%E7%A7%BB%E5%8A%A8%E7%89%A9%E4%BD%93%E7%9A%84%E5%87% A0% E7% A7% 8D% E6% 96% B9% E6% B3% 95 /

1,Actor->SetActorLocation

Actor->SetActorLocation()

2,AActor::AddActorWorldOffset(), AActor::AddActorLocalOffset()

AddActorWorldOffset differs AddActorLocalOffset: If desired Actor moved along the direction of a world coordinate system, and then use the parameters DeltaLocation AddActorWorldOffset world coordinate system; if desired Actor Actor local coordinate system is moved along the direction of the current, then use the relative parameter and AddActorLocalOffset current Actor's DeltaLocation Offset (for example, wanted a spiral track but does not want the world to calculate the spatial coordinates, then use LocalOffset).

If you use AddActorWorldOffset or AddActorLocalOffset move Character, then MovementMode must be set to fly, or when DeltaLocation small, character will always fall down (even if you disable physical simulation), UCharacterMovementComponent::SetMovementMode(EMovementMode::MOVE_Flying);. Or Unpossess Controller.

3,Velocity

ACharacter->GetCharacterMovement()->Velocity += FVector(5.f, 5.f, 0.f);

4, a Controller (PlayerController or AIController) possess the Actor to one, then call:

Controller->MoveTo();

5, a Controller (PlayerController or AIController) possess the Actor to one, then call

GetWorld () -> GetNavigationSystem () -> SimpleMoveToLocation (controller, one location);

Note: If you use Controller-> MoveTo or use NavigationSystem the Move function, provided you use the Navigation components and build the terrain, otherwise invalid.

6,APawn->AddMovementInput

APawn->AddMovementInput(FVector WorldDirection, float ScaleValue = 1.0f, bool bForce = false);

Wherein WorldDirection direction, speed the rate ScaleValue, whether to ignore the attribute value represents the bForce IgnoreMoveInput Controller to forcibly move.

7, UCharacterMovementComponent :: A ddImpulse

void UCharacterMovementComponent::AddImpulse( FVector Impulse, bool bVelocityChange )

AddImpulse generally used for throwing, physics, explosions, blow fly and so on. Added is a moment of force, after each frame do not need to deal with.

Note: AddImpulse role of the object are generally StaticMeshComponent, but can not be CollisionComponent, otherwise invalid. To turn physical and StaticMeshComponent: SetSimulatePhysics (true), otherwise it is invalid.

8, UCharacterMovementComponent :: AddForce

void UCharacterMovementComponent :: AddForce (FVector Force)

If you want an object to keep moving, you need to perform every frame AddForce () function, also said that if the acceleration changes in real time, it can be used AddForce. Difference between the two:
AddForce accounts for delta time and should be used for applying force over more than one frame, AddImpulse does not account for delta time and should be used for single 'pushes', like from an explosion or being thrown by a player. The reason is that if you use AddForce for throwing or an explosion, how far the object moves depends on the framerate at the exact frame the force was applied, rather than being independent of framerate like AddImpulse is.

Reference:
https://forums.unrealengine.com/showthread.php?29496-Addforce-and-addimpulse

9,UKismetSystemLibrary::MoveComponentTo

FLatentActionInfo Action Info;
ActionInfo.CallbackTarget = this;
UKismetSystemLibrary::MoveComponentTo(TopDownCameraComponent, Location, Rotation, false, false, 1.f, true, EMoveComponentAction::Move, ActionInfo);

Usually the body to move Actor Component, e.g. CameraComponent like. To support smooth movement, it may be provided to move the target Location, Rotation long process.

Guess you like

Origin www.cnblogs.com/sevenyuan/p/11850076.html