# Help with programming QuickStart 5

**URL:** <https://forums.unrealengine.com/t/help-with-programming-quickstart-5/328349>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [August 11, 2015, 6:36pm UTC](https://forums.unrealengine.com/t/help-with-programming-quickstart-5/328349 "2015-08-11T18:36:01Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kyle\_Liu\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kyle\_Liu\_1](https://forums.unrealengine.com/u/Kyle_Liu_1)\
**Post date:** [August 11, 2015, 6:36pm UTC](https://forums.unrealengine.com/t/help-with-programming-quickstart-5/328349/1 "2015-08-11T18:36:01Z")

</div>

Hello, I tried searching for this answer on the hub and didn’t have any luck, was wondering if any of you guys would be able to help me out. I’m new here and was following the programming quick start guide and got to the part which asks you to:

Add periodic motion on the X and/or Y axis, and multiply the DeltaTime value by a number between 0.6 and 1.4, so your FloatingActor appears to float around freely. This can look great for powerups!

Was wondering if anyone could tell me how that would like in code.?

Currently I have this in my tick function

```
void AFloatingActor::Tick( float DeltaTime )
{
	Super::Tick( DeltaTime );
	FVector NewLocation = GetActorLocation();
	float DeltaHeight = (FMath::Sin(RunningTime + DeltaTime) - FMath::Sin(RunningTime));

	//NewLocation.X += DeltaHeight * MovementConstant;
	NewLocation.Y += DeltaHeight * MovementConstant;
	NewLocation.Z += DeltaHeight * MovementConstant;
	RunningTime += DeltaTime;
	SetActorLocation(NewLocation);
}

```

How could I make the floating actor seem a little more randomly floating in the air, rather than floating from one end of a diagonal to another? Was playing around with the rand() function, wasn’t sure if that was the right one to use. Any help is appreciated, thanks.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_8e2766aa](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_8e2766aa](https://forums.unrealengine.com/u/anonymous_user_8e2766aa)\
**Post date:** [August 17, 2015, 1:36pm UTC](https://forums.unrealengine.com/t/help-with-programming-quickstart-5/328349/2 "2015-08-17T13:36:21Z")

</div>

Hello,

Please note that you can use `FMath::RandRange` function to get a random number in custom range:

```
static int32 RandRange
(
    int32 Min,
    int32 Max
)

```

However, it is also possible to move the actor instantly to the specified location with `AActor::SetActorLocation` function:

```
bool SetActorLocation
(
    const FVector & NewLocation,
    bool bSweep,
    FHitResult * OutSweepHitResult
)

```

For more complex movement logic you can use **AI Controlled Pawn**.

In Unreal Engine 4, AI functionality is implemented with the help of **Behavior Tree** object. In particular, it has **Move To** function:

![54443-moveto.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/1/7/e17fae714c4d6f58535248814a06ee31ac7c2263.png)

With the help of **Get Random Reachable Point in Radius** node, you can get the TartgetPoint for Move To function:

![54444-getrandomreachablepoint.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/0/3/d03f6b08cfd55654697f5e8081e59cf943f7bb43.png)

If you like to learn more about Behavior Trees in Unreal Engine 4, please go here:

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — https://unrealcommunity.wiki/! You will be able to find content from...

Hope this helped!

Good luck!

---

<div class="post-metadata">

**Author:** ![Denisov-3D](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Denisov-3D](https://forums.unrealengine.com/u/Denisov-3D)\
**Post date:** [August 6, 2016, 1:10pm UTC](https://forums.unrealengine.com/t/help-with-programming-quickstart-5/328349/3 "2016-08-06T13:10:45Z")

</div>

So, what did you use in the end and How did you use it? I would like to know too, because I’m pretty new 😉

---

<div class="post-metadata">

**Author:** ![Denisov-3D](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Denisov-3D](https://forums.unrealengine.com/u/Denisov-3D)\
**Post date:** [August 6, 2016, 1:54pm UTC](https://forums.unrealengine.com/t/help-with-programming-quickstart-5/328349/4 "2016-08-06T13:54:40Z")

</div>

What if I don’t want to use FMath::RandRange? I want to multiply DeltaTime just like it’s saying in the QuickStart tutorial (5 step), but I already tried everything. The question is: where must I multiply the DeltaTime?

---

<div class="post-metadata">

**Author:** ![DennyR](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DennyR](https://forums.unrealengine.com/u/DennyR)\
**Post date:** [August 6, 2016, 2:01pm UTC](https://forums.unrealengine.com/t/help-with-programming-quickstart-5/328349/5 "2016-08-06T14:01:42Z")

</div>

Hey, I would suggest a Curve

```
UPROPERTY(EditInstanceOnly, Category = Tools, DisplayName = "Test Curve")
 UCurveFloat* FloatingMovementCurve;

```

You can edit this curve in the asset browser and then just access it’s values via

```
Curve->GetFloatValue(DeltaSeconds)

```

This gives you or your designers full control over the effect.

Alternatively just make a Timeline in Blueprint and animate the Powerup this way.

---

<div class="post-metadata">

**Author:** ![BujakD](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BujakD](https://forums.unrealengine.com/u/BujakD)\
**Post date:** [August 6, 2016, 4:06pm UTC](https://forums.unrealengine.com/t/help-with-programming-quickstart-5/328349/6 "2016-08-06T16:06:24Z")

</div>

Hello,

Basicly You need to know that to make good looking natural hoovering obove the ground is not so simple task and it can be a little to early for You 😉

using a curve seems to be good idea, but the downvote for it is that it will float always in the same path. Using behaviour tree for something such simple as hoovering powerup is a bit overkill IMHO.

The way it shoul be truly done is to use noise. Noise is a algorithm that gives You numbers that are random but each subsequent is connected with previous and similiar to it so it is good to animate position. Google “Perlin Noise”.

---

<div class="post-metadata">

**Author:** ![DennyR](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DennyR](https://forums.unrealengine.com/u/DennyR)\
**Post date:** [August 6, 2016, 4:26pm UTC](https://forums.unrealengine.com/t/help-with-programming-quickstart-5/328349/7 "2016-08-06T16:26:56Z")

</div>

Well, even though noise gives you nice randomness, I think this is overkill as well. It is just a visual effect. Noise is pretty slow to lookup every frame.  
You could just add another curve for rotation and/or make a curve that handles several periods with some variations. Nobody will ever see a pattern if Rotation and Translation have different period times.

---

<div class="post-metadata">

**Author:** ![GeoffMarshall](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GeoffMarshall](https://forums.unrealengine.com/u/GeoffMarshall)\
**Post date:** [March 28, 2018, 7:33pm UTC](https://forums.unrealengine.com/t/help-with-programming-quickstart-5/328349/8 "2018-03-28T19:33:21Z")

</div>

I just added this:

// Called every frame  
void AFloatingActor::Tick(float DeltaTime)  
{  
Super::Tick(DeltaTime);  
FVector NewLocation = GetActorLocation();  
float DeltaHeight = (FMath::Sin(RunningTime + DeltaTime) - FMath::Sin(RunningTime));  
float DeltaWidth = (FMath::Cos(RunningTime + DeltaTime) - FMath::Cos(RunningTime));  
float DeltaDepth = (FMath::Acos(RunningTime + DeltaTime) - FMath::Acos(RunningTime));

```
NewLocation.Z += DeltaHeight * Amplitude; //Scale our height by amplitude value
NewLocation.Y += DeltaWidth * Amplitude;       
NewLocation.X += DeltaDepth * Amplitude;       
RunningTime += DeltaTime;
SetActorLocation(NewLocation);

```

}
