Spawning projectiles
by Adam Troutman · in Technical Issues · 05/19/2006 (9:08 am) · 64 replies
How would I go about spawning projectiles that shoot down to the ground? having them spawn after pressing a button would be convenient but being able to have them just start up every so often would be best.
#2
05/19/2006 (2:17 pm)
:) Thanks.
#3
05/19/2006 (2:25 pm)
Np, tell me if it worked out alright, it should work fine.
#4
05/19/2006 (2:27 pm)
I put it in default.bind.cs and then put this in moveMap.bind(keyboard, m, testfiring); is that what I am supposed to do, I havent gotten it to work yet but I am probably just doing something dumb.
#5
You must be sure that you have %pos(ition) defined. Do you want it to spawn on a specific object (i.e: Where ever the player is), or will it just spawn at a set position (Above the firepit in orcTown)?
05/19/2006 (2:34 pm)
MoveMap.bindCmd(keyboard, "m", "", "TestFiring(%pos);");You must be sure that you have %pos(ition) defined. Do you want it to spawn on a specific object (i.e: Where ever the player is), or will it just spawn at a set position (Above the firepit in orcTown)?
#6
rtb/client/scripts/msgCallbacks.cs (405): Register object failed for object (null).
Set::add: Object "0" doesn't exist
hmmm.
05/19/2006 (2:40 pm)
I want it to sawn a few feet above my player then shoot down at him. I think I got the mapping right now but im getting this in the console Object 'meteorProjectile' is not a member of the 'GameBaseData' data block classrtb/client/scripts/msgCallbacks.cs (405): Register object failed for object (null).
Set::add: Object "0" doesn't exist
hmmm.
#7
Where %obj is the Players ID. But will also need to add, say 10 to the players height position, so if the players position is "10 5 25" It will need to be "10 5 35", where the projectile starts. It'd need to take that string parse it into 3 values from %xyz to %x %y %z, and add 10 to %z then return it into %x@" "@%y@" "@%z;
This I don't know how to do :(
I miss the olde "String::getSubString()" from Tribes 1 scripting..
And the olde Match:: Functions from presto pack
Also, if you want to practice with %obj.getPosition, go into the editor, find yourself, and your name will be some 4 digit number and a : something like 1730: (For example) if it's 1730, then that's what %obj should be
Echo(1730.getPosition()); Returns your position, 1730.getPosition() can be used as a variable of your position. (Assuming 1730 was the number you found in the editor next to you)
Hope this hasn't been too confusing...
05/19/2006 (2:56 pm)
Hmm, let me think. This will need it to get the players position, that's done with %obj.getPositionWhere %obj is the Players ID. But will also need to add, say 10 to the players height position, so if the players position is "10 5 25" It will need to be "10 5 35", where the projectile starts. It'd need to take that string parse it into 3 values from %xyz to %x %y %z, and add 10 to %z then return it into %x@" "@%y@" "@%z;
This I don't know how to do :(
I miss the olde "String::getSubString()" from Tribes 1 scripting..
And the olde Match:: Functions from presto pack
Also, if you want to practice with %obj.getPosition, go into the editor, find yourself, and your name will be some 4 digit number and a : something like 1730: (For example) if it's 1730, then that's what %obj should be
Echo(1730.getPosition()); Returns your position, 1730.getPosition() can be used as a variable of your position. (Assuming 1730 was the number you found in the editor next to you)
Hope this hasn't been too confusing...
#8
05/19/2006 (3:00 pm)
Well I am confused lol but, okay so say I was in fly mode could I spawn the projectile from my position there and have it shoot directly downward to the ground? The whole getposition I don't understand so much I have used gettransform() to spawn objects at the location of other objects before, would that work for getting the players position?
#9
05/19/2006 (3:00 pm)
Also: About "meteorProjectile", where is the code to define that?
#10
getTransform has something to do with the direction you are looking, I believe, different from getRotation, because I think it also does up/down position (Not sure about this)
getPosition would be the only way to get a players position that I can think of. It works the same way as getTransform, only returns the position, not the transform
05/19/2006 (3:08 pm)
Oops sorry, I missed your post (May 19, 2006 18:00) here is the reply to that one:getTransform has something to do with the direction you are looking, I believe, different from getRotation, because I think it also does up/down position (Not sure about this)
getPosition would be the only way to get a players position that I can think of. It works the same way as getTransform, only returns the position, not the transform
#11
X is North/south
Y is East/West
Z is Up/Down
Z you will want a few more added to, so the projectile spawns above the player, and not right on the center of the player
05/19/2006 (3:11 pm)
It will return 3 values, an X a Y and a Z, X is North/south
Y is East/West
Z is Up/Down
Z you will want a few more added to, so the projectile spawns above the player, and not right on the center of the player
#12
05/19/2006 (3:11 pm)
Okay well meteor projectile is screwed up i changed it to use a projectile i know works which is defined inside a grenade launcher script. So get position would I do something like this %player.getposition(); in the place of %pos here initialPosition = %pos; // Position the projectile will start at
#13
initialVelocity is in the %p datablock
05/19/2006 (3:13 pm)
The initialVelocity tells it 0 0 -10 this means 0 velocity N/S 0 velocity E/W and 10 velocity down, (Negative value = down)initialVelocity is in the %p datablock
#14
05/19/2006 (3:13 pm)
Yeah and so would it also be possible to maybe do something like %pos = getposition() + (0,0,10);
#15
This will make it easier to make a %xyz to %x %y %z converter when time comes (Right now I'm working on rewriting the function to fit your needs [Spawn on player] )
05/19/2006 (3:17 pm)
I've found the getSubStr, I expected it to start with Str, or String, but it started with "get" (getSubStr)This will make it easier to make a %xyz to %x %y %z converter when time comes (Right now I'm working on rewriting the function to fit your needs [Spawn on player] )
#16
VectorAdd(%player.getPosition, "0 0 10");
Ok, back to setting this up, be right back.
05/19/2006 (3:18 pm)
Ah, yes add vector, I forgot about that, Thanks that will make it much more easyVectorAdd(%player.getPosition, "0 0 10");
Ok, back to setting this up, be right back.
#17
05/19/2006 (3:20 pm)
Im not getting any errors anymore with my new projectile, but I am not seeing any explosion either but it will be easier to tell once its shooting off where I want lol.
#18
function TestFiring(%who)
{
%pos = vectorAdd(%who.getPosition(), "0 0 25");
%p = new (Projectile)() {
dataBlock = CrossbowProjectile;
initialVelocity = "0 0 -10";
initialPosition = %pos;
};
MissionCleanup.add(%p);
return %p;
}
Now instead of a position, you input the player's ID for %who
05/19/2006 (3:22 pm)
Aha! it works:function TestFiring(%who)
{
%pos = vectorAdd(%who.getPosition(), "0 0 25");
%p = new (Projectile)() {
dataBlock = CrossbowProjectile;
initialVelocity = "0 0 -10";
initialPosition = %pos;
};
MissionCleanup.add(%p);
return %p;
}
Now instead of a position, you input the player's ID for %who
#19
-Edit- Spelling
05/19/2006 (3:24 pm)
Now I'm trying to find an easier way to get a player's ID (Other than going into the editor, and looking for yourself) THere must be an easier way somewhere, I remember a getControlObjectID or something, returns the ID of the object you're controlling, somewhere (Looking, be right back)-Edit- Spelling
#20
05/19/2006 (3:25 pm)
The players id I havent figured out how you get that, and does it change every time you enter the game, or in multiplayer games?
Torque Owner Alex Huck
Default Studio Name
Function TestFiring(%pos)
{
%p = new (Projectile)() { // You are telling the game that your are creating a new Projectile, naming it %p
//Below are the attributes of the projectile (%p)
dataBlock = CrossbowProjectile; // The default CrossBow Projectile will shoot
initialVelocity = "0 0 -10"; // Negative 10 is how fast downward it moves
initialPosition = %pos; // Position the projectile will start at
};
// Tell the game to spawn %p
MissionCleanup.add(%p);
return %p;
}
//Then type in console "TestFiring(*Insert position here*);" (Position being the group of 3 numbers found in the inspector)
// I don't know if there is a better way to get a position than looking in the inspector, besides %obj.GetPosition() Post if you want more information on %obj.getPosition();
-Edit- (Commented code for better understanding)
-Edit2- More comments