How to "spin" a rotator?

Hey all,

I’m trying to add bullet spread (inaccuracy) to my weapon; it’s hard to describe in words, so here’s a diagram:


Now, that’s what should happen.

But when I try to add the “Spin” in step two, it doesn’t work, nothing changes. My dots end up in a straight line, only randomized because of the pitch angle. I think Unreal is trying to add the roll relative to the already rotated angle, not the original frame of reference, so nothing happens. So, how can I add to a rotator, relative to the original rotation? (I tried adding the roll first, it didn’t help.)

I hope I’ve been clear enough; if not, please say so!

EDIT: haha, forgot to post my code.

I can’t actually help you because I’m at work, but I can tell you why you’re having that problem. Hopefully someone else can fill in the blanks.

You need to remember that when you add Pitch, Roll or Yaw to a Rotator, you’re adding it in LOCAL space - or - you’re applying those transforms relative to the rotators current position. What you really want to be doing is taking a copy of your original rotator, let’s call it GunRotator and making a BulletRotator. You then rotate BulletRotator on BulletRotator.pitch by your random arc. You then want to rotate BulletRotator, as a whole, by a random degree of roll from GunRotator… so we’re saying, rotate our offset BulletRotator by GunRotator’s roll.

I can’t help you with the actual code, but;
BulletRotator = GunRotator
BulletRotator.pitch += random()
// TODO: Magic where BulletRotator is now moved relative to GunRotators roll, by a random degree.

Yes, this is EXACTLY what I want to do! :smiley: But how do I do it? Is there a special “MoveRelativeToOtherRotator” function that I’m missing or something?

Still can’t help you as I haven’t been near the code today and the docs are still down.

You could do a quick-and-dirty version of this by just adding a random value to the rotators Pitch and Yaw respectively. If you fire enough bullets your pattern would come out square, so this totally isn’t the right way to do it, but it’ll get you out of this snag and can be fixed later when someone posts the solution.

Haha, that’s what I was doing in UDK :smiley: I wanted to actually do it properly this time though. Still, it’ll tide me over until I, you, or somebody else can figure this out. :slight_smile:

If you’re doing this in code, check out the VRandCone() functions in UnrealMathUtility.h. They’ll return a vector within a specified cone, uniformly distributed. Perfect for weapon spread. :slight_smile:

Those seem like good functions to expose to Blueprint, actually – I’ll look into that. :slight_smile:

Thanks Jeff! Didn’t know that function existed, will definitely come in handy :slight_smile:

And, by examining the definition for it, I figured out that the function I was looking for earlier is FVector::RotateAroundAxis, which, as it says, rotates a vector around a custom axis. So my original question is also answered :smiley: Thanks!