PDA

View Full Version : Modifying Vectors


SoSilencer
17th Sep 2001, 10:42 PM
I've been working on a new type of rocket for the past 7 hours or so. My goal is to make a seeking rocket that follows a path which "wobbles". It's hard to explain I know. I can almost get it to work but I have two problems. What is the proper way to modify a vector?

rRand.Pitch = (rand(4097)-2048);
rRand.Yaw = (rand(4097)-2048);
rRand.Roll = (rand(4097)-2048);
vRand = Vector(rRand);
RocketDir = Normal(SeekingDir + vRand);

This is what that code SHOULD do in my mind, which obviously isn't working properly cus that doesn't work.

First I made a random number between 0 and 4096, then subtract 2048 leaving me with a number between -2048 and 2048. I do that for the pitch, yaw, and roll of rRand then make a vector with those rotation properties. I should have a vector that is +-2048 in all axis. Then I take the normal of the SeekingDir (vector to target) and the vRand (the random vector I just made) and add them together. From the tutorials I read I thought that was supposed to add the two vectors together which should basically SeekingDir and make it +-2048 for all axis.

When I load it into the game however it completely ignores the SeekingDir and the rockets only fly due east. They wobble with the +-2048 in all directions but the original vector they are wobbling off is east and not the SeekingDir like it should be.

My other problem is that the rockets are a little too accurate, as in they never miss. I tried finding the difference between the direction I want the rocket to travel in (seek + rand) and the direction the rocket was currently traveling in but I couldn't figure out how to compare them like that. I figure if I can get the difference between them I can make sure it's not too great (rocket is turning too fast) and if it is I can reset it back to the max value.

The regular ut seeking rocket works fine but I don't really understand all that code. For example the line that says Accellerationr = 25 * SeekingDir (I think). Sure that makes sense when you first read it but looking at the code (and the classes above it) I don't find anything that actually USES the accelleration setting so I can't figure out how it effects the flight since there is no code that uses it.

Anyways, if anyone could help me with adjusting/adding/comparing vectors I'd really appreciate it. Nomatter what I try the solution to those problems seems to keep slipping through my fingers.

Dragonfly_of_Forgery
18th Sep 2001, 12:59 AM
To decrease the accuracy, make the rocket not turn fully towards its target. Give it momentum. Something like this:

rRand.Pitch = (rand(4097)-2048);
rRand.Yaw = (rand(4097)-2048);
rRand.Roll = (rand(4097)-2048);
vRand = Normal(SeekingDir + Vector(rRand));
RocketDir = Normal(RocketDir * 0.5 + SeekingDir);

Then adjusting that "0.5" will make it turn more or less towards the target. If the "0.5" was changed to a 1, the rocket would turn half-way between where it was going and where the target was each time you called this function.

I'm not sure about the due east thing but are you sure that SeekingDir is actually pointing somewhere and isn't set to 0,0,0?

SoSilencer
18th Sep 2001, 12:43 PM
I figured out what it was. I needed to convert both vectors to rotations first, then add them, then convert them back into vectors. I'm not exactly sure why but I have a feeling it's because the random vector I made had a speed of 0.

SeekingVect = (Seeking.Location - Location);
SetRotation(Rotator(SeekingVect));
SeekingDir = Rotation;

RocketDir.Pitch = SeekingDir.Pitch + (Rand(4097) - 2048);
RocketDir.Yaw = SeekingDir.Yaw + (Rand(4097) - 2048);
RocketDir.Roll = SeekingDir.Roll + (Rand(4097) - 2048);
RocketVect = vector(RocketDir);

The turn radius works now too so thanks for the help with that.