• News
• About

• Industries

• Learning & Support

• Community

• Marketplace

Download # [Question] Random rotations.

Hi,

I was wondering how I could use random float values to let rotations happen randomly either in positive or negative (left or right for example).

Suggestions?

Edit: Do not want to use a random rotator, but float values with a min rotation speed and max rotation speed like in the image below. Well I found something. Here was the solution for me in case any other newbs need to know this information.  Wouldn’t this work?

I don’t believe it would since I am using user input (exposed variables) for the rotations. I want the variable to act as a speed, and then it randomizes from those values with negatives and positives. The user shouldn’t have to think about the negatives. Just the min and max speed.

Hi,
thought I add the question to this thread. I want to create a random yaw rotation for my WindDirectionalSource. If I “hard-code” a number and create a transform everything works fine, but as soon as I try to create a random float via the node “random float in range” and plug it into the Yaw Rotation, the Yaw always ends up to be different than it does actually generate. I added a print node to the end of my node-chain to check and it doesn’t really work. For example the random float is a 160 and the Yaw of my object is -27 or something like that. Any idea why that is ? Also tried “SetActorRotation” Node, same behaviour. There are multiple ways of doing random rotations. Your example qill give some “weird” rotations (until you imagine how angles are counted in 3d space).

Instead of creating random rotation I use random vectors then i am changing them into rotations with “Find look at rotation node” (if you put vector as destination and [0,0,0] as start you get rotation out of vector. Vectors are easier to imagine and undestand than rotators. Vectors also do not have polar singularity or gimball effect.

For your “slightly to the left” random vector:

• Get forward vector of your pawn
• pick random rotation
• rotate forward vector by that random rotation around up vector of pawn vector. use “rotate vector around axis” node
• Above vector will point in random direction to left or right depending on angle. It is left/right in pawn reference frame
• now get random vector in cone, as axis use above vector, angle is cone angle
You should have now random vector than needs to be translated into rotation. For that it is best to use “find look at rotation”.

There are also other nodes that are like “make rot from XY”, you supply them with pairs of forward, up right vector, depending on name of node) There is also node that makes rotation out of single vector, but you kind of get random vector that is perpendicular to direction. So find look at rotation is easiest to use.

That seems to be quite complicated. So I can’t just type my 0-360 degree number in the Yaw of my objects’ transform to do it ? Why does it work when I hard-code it ? Basically the random float in range node just gives me a random number in the desired range, doesn’t it ? Seems quite strange to me UPDATE

So I tried different nodes now and this works: I think I got it. Its because if I print out the random number AFTER the “SetActorRotation” and don’t store it in a variable then of course it generates a NEW random number just a few milliseconds after executing the node before for the print node. Quite simple actually, sorry for the noob question…also it seems it can only read values between -180 to 180 and not 0-360