[ad_1]
I am coming from the Unity Engine, and trying to get my feet wet with Unreal Engine 4.8.x. I want to add a one-time force to an object. To accomplish this in Unity 5, I would use:
void Start(){
GetComponent<Rigidbody>().AddForce(new Vector3(0, 0, 5));
}
Explanation:
GetComponent<Rigidbody>()
retrieves theRigidbody
Component. TheRigidbody
is
already attached to theGameObject
.
TheAddForce
method is called on theRigidbody
, and applies the force of
aVector3
. The parameters of theVector3
indicate the force on each
axis which is applied. In the example above, theGameObject
would
move forward on its z-axis.
How would I accomplish this same thing in Unreal Engine 4? I would appreciate if you can elaborate on what exactly is happening in the code as well. I currently have an empty AActor script, and I am struggling to find out what to put in my BeginPlay() method.
void AMyActor::BeginPlay()
{
Super::BeginPlay();
//What goes here? Why?
}
As CobaltHex pointed out, UPrimitiveComponent has a UPrimitiveComponent.AddForce(FVector, BoneName)
method. However, I cannot figure out how to use it. The real objective of this question is as a basic introduction to programming with Unreal Engine. I chose AddForce, because it is an extremely commonly used method with a visible effect (in Unity). All of the existing tutorials are either with an older version of unreal (which has different scripting) or are using blueprints (which has no scripting). That is why I am trying to figure out what the actual code would be and what that code does.
Specifically, I am looking for an answer which tells me what code is missing from my Unreal Engine script, and what that code does, similiarly as is presented with my Unity Engine example.
[ad_2]