Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → Vectors and Velocities
Vectors and Velocities
2003-05-16, 7:58 AM #1
I need to know how to get a bullet to travel in the opposite direction with a random offset.

This is for saber blocking.

To make it go in the opposite direction I do setthingvel(bullet, vectorscale(getthingvel(bullet), -1)); now I just need to know how to apply a random offset to that.

Any help would be greatly appreciated.

------------------
"Anakin, when I tried to earn my knighthood by defeating a Sith Lord, I actually WON."
-Obi Wan Kenobi
2003-05-16, 11:55 AM #2
For saber blocking? I thought they automatically bounced back (using some flag on the player or saber). Hmm... Lemme go look...

------------------
"The Just shall live by faith." - Galatians 3:11

[This message has been edited by DogSRoOL (edited May 16, 2003).]
Catloaf, meet mouseloaf.
My music
2003-05-16, 12:39 PM #3
Well they automatically bounce back, but I'm completely redoing saber blocking via cog, so for my purposes they don't.

------------------
"Anakin, when I tried to earn my knighthood by defeating a Sith Lord, I actually WON."
-Obi Wan Kenobi
2003-05-16, 6:06 PM #4
Well...
You could try multiplying the vector by -1 (not sure if that's possible by simple math). You'll probably have have to rip the vector into XYZ components to do that, then reassemble it using 'VectorSet(x, y, z);' That should flip the velocity to the opposite direction. For the random, you could multiply one of the XYZ components by 'Rand()', but you'll probably need to tweak that, too.

**tries to visualize vectors, but someone is using a jedi mind trick on him**

------------------
"The Just shall live by faith." - Galatians 3:11

[This message has been edited by DogSRoOL (edited May 16, 2003).]
Catloaf, meet mouseloaf.
My music
2003-05-17, 3:23 PM #5
Simply make a new vector that has random components from 0 to the max offset and add it to the vecotr you want to offset. That solution is presuming you don't mind the speed of the object changing, etc. If you want a better solution that only changes the direction within a certian maximum angle, just let me know. I'll check back here in a while.
And meanwhile the bus with legs has destroyed half of disneyland . . . and nobody cares!
2003-05-18, 5:36 AM #6
Multiply each element in the vector by -1. I think that will reverse it.

------------------
Bassoon, n. A brazen instrument into which a fool blows out his brains.
Bassoon, n. A brazen instrument into which a fool blows out his brains.
2003-05-18, 9:35 AM #7
To those who tell me to multiply by -1: I pasted a line of code that multiplies by -1, so I already know how to do that.

To both of you who told me 'multiply by -1 and vectoradd a randvec': - You're l33t. Thanks.

------------------
"Anakin, when I tried to earn my knighthood by defeating a Sith Lord, I actually WON."
-Obi Wan Kenobi
2003-05-18, 10:00 AM #8
I take it that means you're not too worried about the velocity slightly changing? Good. I didn't want to have to convert that messy math into cog. If you still want it though I'll do it.
And meanwhile the bus with legs has destroyed half of disneyland . . . and nobody cares!
2003-05-18, 10:19 AM #9
ok, now I have a new problem:

The bouncing thing works, but occasionally the bullet comes out behind the player on block.

Here's the code:
Code:
        traj=vectorscale(getthingvel(molester), -1);
        stopthing(molester);
        clearweaponflags(molester, 0x1);
        randVec = VectorSet((Rand()-0.5)*5, (Rand()-0.5)*5, 0.0);
        angle=vectoradd(traj, randvec);
        setthingvel(molester, angle);


molester is the bullet, and this goes in touched: message.


------------------
"Anakin, when I tried to earn my knighthood by defeating a Sith Lord, I actually WON."
-Obi Wan Kenobi
2003-05-18, 4:09 PM #10
I don't think you need the "stopThing" command. 'SetThingVel' doesn't (that I recall) take into account the current velocity like 'applyforce' does.

------------------
"The Just shall live by faith." - Galatians 3:11

[This message has been edited by DogSRoOL (edited May 18, 2003).]
Catloaf, meet mouseloaf.
My music
2003-05-18, 7:30 PM #11
Actually, it hardly worked worth a crap without the stopthing.

I don't know why.

------------------
"Anakin, when I tried to earn my knighthood by defeating a Sith Lord, I actually WON."
-Obi Wan Kenobi
2003-05-19, 12:07 PM #12
Does it go behind the player when you're standing still?

------------------
"The Just shall live by faith." - Galatians 3:11
Catloaf, meet mouseloaf.
My music
2003-05-19, 2:06 PM #13
Quote:
<font face="Verdana, Arial" size="2">I take it that means you're not too worried about the velocity slightly changing? Good.</font>


If you want to fix that, normalize the vector and then multiply it by the speed the bullet should have (the length of the original vector).

Quote:
<font face="Verdana, Arial" size="2">occasionally the bullet comes out behind the player on block.</font>


You mean the bullet goes through the player, or it reappears behind him when your code runs? Need some more info there.

I'm not sure why StopThing() needs to be there, it's not obvious.

BTW, your code would be a little easier to understand if you used the right terms. A trajectory is a direction - which I would define as a vector with a length of one. But you're using it as a velocity. Velocity is a vector for direction and speed. And an angle isn't a vector.

------------------
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.

[This message has been edited by SaberMaster (edited May 19, 2003).]
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2003-05-19, 5:38 PM #14
Bah, that's the easy way of doing it! Also, with the way it's being done now there is a greater possible deflection angle for some deflection directions than others. The other way I was thinking of doing it would be to select a direction and magnitude of deflection randomly and then multiply the velocity vector by a rotation matrix, but that's messy.
And meanwhile the bus with legs has destroyed half of disneyland . . . and nobody cares!

↑ Up to the top!