How to rotate a vector?

Discussions about Coding and Scripting
Post Reply
User avatar
Barbie
Godlike
Posts: 2792
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

How to rotate a vector?

Post by Barbie »

While modding a map for MH I run into the task to create a pinball ball that is just flying (linear) around in a walled area, being reflected at walls and damaging players if that ball hits him. To give the trajectory a bit randomness I'd like to change the direction (but not the length) of the resulting velocity vector after a wall hit. For now I've been using this, but I'm sure there is an easier way:

Code: Select all

var(Movement) int BounceVariance;

simulated function float VaryValue(float Value, int Vary) {
	return (1 - 2 * fRand()) * Vary + Value;
}

simulated function HitWall(vector HitNormal, actor Wall) {
local rotator r;
[... code of Mover(Wall).bDamageTriggered left out ...]
	if (BounceVariance != 0)
	{
		r = rotator(HitNormal);
		r.yaw = VaryValue(r.yaw, BounceVariance);
		r.pitch = VaryValue(r.pitch, BounceVariance);
		r.roll = VaryValue(r.roll, BounceVariance);
		HitNormal = Normal(vector(r));
	}
	Velocity = MirrorVectorByNormal(Velocity, HitNormal);
}
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
Post Reply