x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Help with programming QuickStart 5

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.

Product Version: UE 4.8
Tags:
more ▼

asked Aug 11 '15 at 06:36 PM in C++ Programming

avatar image

Kyle Liu
1 1 2

avatar image Denisov-3D Aug 06 '16 at 01:10 PM

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 ;)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

3 answers: sort voted first

Hello, Kyle

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:

alt text

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

alt text

If you like to learn more about Behavior Trees in Unreal Engine 4, please go here: https://wiki.unrealengine.com/Blueprint_Behavior_Tree_Tutorial

Hope this helped!

Good luck!

more ▼

answered Aug 17 '15 at 01:36 PM

avatar image

Andrii Melnyk
1.8k 60 19 112

avatar image Denisov-3D Aug 06 '16 at 01:54 PM

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?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

more ▼

answered Aug 06 '16 at 02:01 PM

avatar image

DennyR
1.1k 31 12 47

avatar image BujakD Aug 06 '16 at 04:06 PM

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".

avatar image DennyR Aug 06 '16 at 04:26 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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);

}

more ▼

answered Mar 28 '18 at 07:33 PM

avatar image

GeoffMarshall
1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question