How to rotate a vector?

Discussions about Coding and Scripting

How to rotate a vector?

Postby Barbie » Wed Mar 08, 2017 1:26 am

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
User avatar
Posts: 1607
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Return to Coding, Scripting

Who is online

Users browsing this forum: No registered users and 1 guest