Author Topic: Adding spread to a projectile  (Read 536 times)

'matrixMulVector'
'vectorCross'
'vectorDot'
'vectorOrthoBasis'

What the heck do these do? I was messing around with vectors and found these.

Also:
      for(%i=0;%i<%num;%i++) {
         %r = 6.28318530;
         %nvel = %vel;
         %theta = mcos(getrandom(0, 1000)/1000 * %r);
         %pitch = msin(getrandom(0, 1000)/1000 * %r);
         %theta -= %pitch;
         %sx = %spread * %theta;
         %sy = %spread * msin(macos(%theta));
         %sz = %spread * %pitch;
         %nvel = vectorAdd(%nvel, %sx SPC %sy SPC %sz);
         %obj.spawnProjectile(%proj,%nvel,%scale,%slot);
      }

I assume i'm either doing something very wrong here or there's a much better way to do this.
Or both.

(all variables have been defined already if they're not defined here)
« Last Edit: July 10, 2012, 10:58:50 AM by ThinkInvisible »

It's not something that can be explained in depth easily without a basic grounding in trig
They're all math equations, and all this code is doing is transforming a given maximum angle of variance into a three-component vector for the engine to use

It's not something that can be explained in depth easily without a basic grounding in trig
They're all math equations, and all this code is doing is transforming a given maximum angle of variance into a three-component vector for the engine to use
I had it solved once, I just forgot how to do it. :/

If you're satisfied with the travel velocity of the projectiles changing slightly, you can simply generate a random vector and add that to the original velocity. That seems to work really well for me.

If you're satisfied with the travel velocity of the projectiles changing slightly, you can simply generate a random vector and add that to the original velocity. That seems to work really well for me.
I'll use that for now, but I still want to remember how to convert vectors like that. The main problem with plain getRandom is that it makes a square spread area instead of a circle.

What type of gun fires bullets in a square pattern? >:V
« Last Edit: July 10, 2012, 11:34:11 AM by ThinkInvisible »

What you want for this is for getRandom to generate random degrees, not random vector components

Here's a explination of Treynolds post:


...

In other words, calculate a random left and up angle, and then adjust the vector based on the equation original/cos(offset)
« Last Edit: July 10, 2012, 12:38:50 PM by Ipquarx »


   %theta = getrandom(0, 90);
   %pitch = getrandom(0, 90);
   %nvel = vectorAdd(%nvel, 2 * mcos(%theta) SPC 2 * msin(%theta) SPC 2 * mcos(%pitch));


seems to work perfectly
thanks

Just so you know, the trigonometric functions in TorqueScript take radians.