Game Development Community

Negative Velocity method?

by Lee Latham · in Torque Game Engine · 02/08/2007 (2:09 pm) · 8 replies

I kinda hate to post when I don't really have a problem--the script code below works just fine for creating a negative velocity vector. However, I can't help feeling that there surely is a more elegant way to do it? I want to be a good scripter.

%vel=%this.getVelocity();
	
	%word0 = getWord(%vel, 0);
	%word1 = getWord(%vel, 1);
	%word2 = getWord(%vel, 2);
	
	%word0=-%word0;
	%word1=-%word1;
	%word2=-%word2;
	
	%vel = setWord(%vel, 0, %word0);
	%vel = setWord(%vel, 1, %word1);
	%vel = setWord(%vel, 2, %word2);

Any thoughts?

#1
02/08/2007 (2:23 pm)
Try VectorScale(%vel, "-1 -1 -1");
#2
02/09/2007 (3:34 pm)
ROFLMAO. Yes, that would be a little more efficient, wouldn't it?

Thanks! hehe. Shoulda thought of that....
#3
02/09/2007 (4:44 pm)
Chris is absolutely right,
but a side note is that instead of using setWord, you could have done:
%vel = %word0 SPC %word1 SPC %word2;
#4
02/10/2007 (1:21 am)
Oh wow. Now that I would never have guessed. I take it that's a fairly Torquescript or scripty in general sort of deal? I had thought you could only do that in an echo statement.

But I guess that was an assumption of mine. Veeery Innterrreesting!
#5
02/10/2007 (7:52 pm)
Not sure where you're using this code and what for, just letting you know you can also use a physical zone (available via mission editor) to apply negative velocity (amongst other things).
#6
02/11/2007 (1:10 am)
Err? You mean like a trigger?

I'd never noticed that before--I just went and found it. How does it work? Sounds interesting!
#7
02/11/2007 (5:52 pm)
Almost like a trigger. You draw out a physical zone, set the parameters for that physical zone (velocity, gravity etc) and when your player enters that zone the altered values are applied to the player. One example usage would be a jump pad.
#8
02/11/2007 (5:59 pm)
Wow. I _really_ wish I'd known about those a long time ago. Thanks!

Guess that's what I get for not reading the instructions.