Magnetism
by Jeff Trier · in Torque Game Engine · 01/29/2004 (6:31 pm) · 5 replies
Hey all,
How can I get a player object to be "pulled/pushed" to a vector location without using a Trigger or PhysicalZone? The reasons I don't want to use either Triggers or PZ's are...
1) I don't want to pull more than the desired object.
2) The magnetic area will be dynamic in location. That is, they will be created and destroyed at various locations regularly.
I am guessing that I need some vector math for this. Now mind you, I am very new at vector math so don't throw eggs when I show you what I have tried... :)
%obj = %client.player;
%dif = vectorSub(%magnetLoc,getWords(%obj.getTransform(),0,2));
%obj.setVelocity(%dif);
My idea here was to get the difference between the player's location and the magnets location, then use setVelocity to propel the player object to the magnets center. Since the above didn't work, I have a feeling that I am way off... duh! lol
Any help would be great.
Thanks!
-Jeff
How can I get a player object to be "pulled/pushed" to a vector location without using a Trigger or PhysicalZone? The reasons I don't want to use either Triggers or PZ's are...
1) I don't want to pull more than the desired object.
2) The magnetic area will be dynamic in location. That is, they will be created and destroyed at various locations regularly.
I am guessing that I need some vector math for this. Now mind you, I am very new at vector math so don't throw eggs when I show you what I have tried... :)
%obj = %client.player;
%dif = vectorSub(%magnetLoc,getWords(%obj.getTransform(),0,2));
%obj.setVelocity(%dif);
My idea here was to get the difference between the player's location and the magnets location, then use setVelocity to propel the player object to the magnets center. Since the above didn't work, I have a feeling that I am way off... duh! lol
Any help would be great.
Thanks!
-Jeff
About the author
Originally a Classical/Metal musician, I've always been attracted to anything involving computers, including: Networking, PC Building and Repair, software design and coding. I've been involved with game design and development for over 10 years.
#2
I got it to work using vectorScale and vectorNormalize (I wondered what that did!). I am glad I wasn't too far off... Yay! :)
Thanks again,
-Jeff
01/30/2004 (5:03 pm)
Thanks a lot Martin.I got it to work using vectorScale and vectorNormalize (I wondered what that did!). I am glad I wasn't too far off... Yay! :)
Thanks again,
-Jeff
#3
Off the top of anyones head, how would 1 meter equate into world coordinates. Say for example I started at 0 0 0 and ran up the 'Y' axis for 1 meter, what would the difference be?
Thanks guys,
-Jeff
02/02/2004 (11:02 am)
Btw...Off the top of anyones head, how would 1 meter equate into world coordinates. Say for example I started at 0 0 0 and ran up the 'Y' axis for 1 meter, what would the difference be?
Thanks guys,
-Jeff
#4
About your Trigs or PZ's. What I would do is create a new armor variable called ".canAttract = true;" or ".magnetic = true;" or something like that. When you do the area check around your magnet, just check whatever objects you find to see - if(%obj.canAttract){then pull it;} else{}
You could also use the
vectorDistance(player.getPosition(), magnet.getPosition());
function to get your distance as well. Since magnets are omnidirectional, finding the rotation of both the player and the magnet seems wasteful(if you have a need, then let me hush) And then you'll need to apply an impulse to the player to push him in the correct direction. Since you can apply the ".canAttract" to any object to any object you choose, you will be able to magnatize exactly what you want, and all others will be ignored
Hope that was what you were asking about, I'm a little slow tonight, lol
02/02/2004 (4:23 pm)
1 is 1. Meaning that 1 meter in Torque is about what it looks like. In reality, measurement can be any scale you choose. If it looks like a mile, and you say its a meter, then its a meter. Thats the beauty of programming, lol.About your Trigs or PZ's. What I would do is create a new armor variable called ".canAttract = true;" or ".magnetic = true;" or something like that. When you do the area check around your magnet, just check whatever objects you find to see - if(%obj.canAttract){then pull it;} else{}
You could also use the
vectorDistance(player.getPosition(), magnet.getPosition());
function to get your distance as well. Since magnets are omnidirectional, finding the rotation of both the player and the magnet seems wasteful(if you have a need, then let me hush) And then you'll need to apply an impulse to the player to push him in the correct direction. Since you can apply the ".canAttract" to any object to any object you choose, you will be able to magnatize exactly what you want, and all others will be ignored
Hope that was what you were asking about, I'm a little slow tonight, lol
#5
I didn't know about vectorDistance, thanks for pointing that function out. :)
As far as scaling goes, I see what you mean. But for simplicity's sake, I want to keep to Torque's scale of measurement. I am assuming that since the playerData's "maxForwardSpeed" was set in "meters per second", there must be an indication of how long a meter actually is in vectors. Knowing this would be very helpful.
I think I am going to have to wait until I get home and do a series of tests.
Thanks for the reply!
-Jeff
02/02/2004 (4:38 pm)
Hi Kenneth,I didn't know about vectorDistance, thanks for pointing that function out. :)
As far as scaling goes, I see what you mean. But for simplicity's sake, I want to keep to Torque's scale of measurement. I am assuming that since the playerData's "maxForwardSpeed" was set in "meters per second", there must be an indication of how long a meter actually is in vectors. Knowing this would be very helpful.
I think I am going to have to wait until I get home and do a series of tests.
Thanks for the reply!
-Jeff
Torque 3D Owner Martin "Founder" Hoover
Also, depending on the target you will probably find that when it is dragged along the ground, that the terrain interferes with the movement, which would require that you seperate the members of the scaled vector so you can add a lil extra oomph to the z to bump the target into the air a bit (Provided you have terrain in the first place).
%nDif = vectorNormalize(%dif);
%sDif = vectorScale(%nDif, 20);
%vel = getwords(%sDif, 0, 1) SPC getWord(%sDif, 2) + 3.75;