Link Points
by Ben Sparks - Warspawn · in Torque Game Builder · 03/05/2005 (1:12 pm) · 9 replies
Hi all,
In the tutorial you add a link point to the player ship for the correct location to fire projectiles from. I'm wondering how one knows exactly where on their image they want to put that link point? I assume that it's world coordinates based on the "world" of that individual sprite? Also, I've been trying trial and error, but somehow no matter what I put in there it keeps shooting from the center of the sprite....
here are my two functions if it helps...
So, a) if you can tell me what im doing wrong as to why it only shoots from the origin of the sprite b) how do I find the values that I want to put in there based on my what my image looks like.
Thanks,
-Warspawn
In the tutorial you add a link point to the player ship for the correct location to fire projectiles from. I'm wondering how one knows exactly where on their image they want to put that link point? I assume that it's world coordinates based on the "world" of that individual sprite? Also, I've been trying trial and error, but somehow no matter what I put in there it keeps shooting from the center of the sprite....
here are my two functions if it helps...
function createPlayer()
{
$player = new fxStaticSprite2D() { scenegraph = t2dSceneGraph; };
$player.setGroup( 1 );
$player.setLayer( 1 );
$player.setImageMap( playershipImageMap );
$player.setPosition("0 30");
$player.setWorldLimit( clamp, "-49 -37 49 37" );
$player.fireLinkPoint = $player.addLinkPoint( "0 1" );
}
function playerFire()
{
// create player projectile
$projectile = new fxStaticSprite2D() { scenegraph = t2dSceneGraph; };
$projectile.setPosition( $player.getLinkPoint($player.fireLinkPoint) );
$projectile.setSize( "3 1.5" );
$projectile.setRotation( "90" );
$projectile.setImageMap( playermissileImageMap );
$projectile.setWorldLimit( kill, "-60 -60 60 60" );
$projectile.setLinearVelocityY( -30 );
}So, a) if you can tell me what im doing wrong as to why it only shoots from the origin of the sprite b) how do I find the values that I want to put in there based on my what my image looks like.
Thanks,
-Warspawn
About the author
I'm a web developer by day, hobbyist game developer by night.
#2
Yeah it looks good to me too. Yet the linkpoint remains at 0,0 local coords on the sprite. I'm doing a top scrolling shooter instead of a side shooter, so I wanted to have it shoot from the top center of my image (0,1). I've tried though changing it to any value, and it still doesn't change.
(Also, im using that HelperGui to show me where the linkpoint is, so I can see that it isn't moving)
I suppose also that as far as the best way to figure out the points to put it is guessing? Or is there a math thing you can do using the size of the sprite to 1.0 and dividing based on pixels?
Thanks,
-Warspawn
03/05/2005 (2:00 pm)
Thanks for the response...Yeah it looks good to me too. Yet the linkpoint remains at 0,0 local coords on the sprite. I'm doing a top scrolling shooter instead of a side shooter, so I wanted to have it shoot from the top center of my image (0,1). I've tried though changing it to any value, and it still doesn't change.
(Also, im using that HelperGui to show me where the linkpoint is, so I can see that it isn't moving)
I suppose also that as far as the best way to figure out the points to put it is guessing? Or is there a math thing you can do using the size of the sprite to 1.0 and dividing based on pixels?
Thanks,
-Warspawn
#3
Let us know if you hit a problem trying this!
Re: setting the link point... yeah, what I do is open up the image in an image editing program, then pick a pixel I want for the link point. Take that pixel's (x,y) position... divide the x by the image's total horizontal width, and the y by the vertical height. Now subtract 0.5 from both and you have your local-space link point coordinate. Of course, another method is just to guess-and-check repeatedly. After a few tries, you'll be there, and since you can change linkPoints in real-time using the console (~ key), it's really quick to do it this way.
Believe me, we both know this is not the easiest way to set-up stuff like this. It's nasty. :) This is the roughest part of doing a game in T2D right now, and it will go away when we release the SceneObject Editor (not sure if it'll be called that in the end). With the SceneObject editor, you'll be able to just click a point on the image to define it as the link point. Likewise for mounts, and you'll be able to click-and-draw collision polygons, etc, etc, etc. It'll be nice.
It's a little way out before this'll be released, but stay tuned!
03/05/2005 (2:35 pm)
You're not doing anything wrong in that code, unless I'm missing some typo. Just an exercise in debugging, try going into the spacescroller directory, opening player.cs and editing the fireLinkPoint call to use "0 1" as you are here. Does work in the spacescroller? (Sorry not to do this directly myself, just trying to help get everyone in a "debug" mindset... teach a person to fish vs give them a fish, etc :)Let us know if you hit a problem trying this!
Re: setting the link point... yeah, what I do is open up the image in an image editing program, then pick a pixel I want for the link point. Take that pixel's (x,y) position... divide the x by the image's total horizontal width, and the y by the vertical height. Now subtract 0.5 from both and you have your local-space link point coordinate. Of course, another method is just to guess-and-check repeatedly. After a few tries, you'll be there, and since you can change linkPoints in real-time using the console (~ key), it's really quick to do it this way.
Believe me, we both know this is not the easiest way to set-up stuff like this. It's nasty. :) This is the roughest part of doing a game in T2D right now, and it will go away when we release the SceneObject Editor (not sure if it'll be called that in the end). With the SceneObject editor, you'll be able to just click a point on the image to define it as the link point. Likewise for mounts, and you'll be able to click-and-draw collision polygons, etc, etc, etc. It'll be nice.
It's a little way out before this'll be released, but stay tuned!
#4
I'll keep digging in my own code til I find the (undoubtedly simple) error in it...
Got another question though, what is the console command to change the link points at runtime?
Thanks,
-Warspawn
03/05/2005 (2:51 pm)
Cool thanks. So yes, I changed it in the demo and it moved correctly...I'll keep digging in my own code til I find the (undoubtedly simple) error in it...
Got another question though, what is the console command to change the link points at runtime?
Thanks,
-Warspawn
#5
For some reason I don't understand it requires that you use the setSize command. After setting the size of the image, it works. Although, without doing that the whole image showed up, and the size was perfect. So, I'm not sure as to the reason why you have to set the size (I thought it would only be if you needed to resize it).
Thanks,
- Warspawn
03/05/2005 (5:09 pm)
Ok, I figured it out...For some reason I don't understand it requires that you use the setSize command. After setting the size of the image, it works. Although, without doing that the whole image showed up, and the size was perfect. So, I'm not sure as to the reason why you have to set the size (I thought it would only be if you needed to resize it).
Thanks,
- Warspawn
#6
03/05/2005 (11:28 pm)
Thanks Ben. Yeah actually, this might be a bug. Can't remember whether we wanted that to be required behavior or not, but if we did, I think we were mistaken to. :) Anyway, we'll look at changing it, or at least of making a note of this req in the docs.
#7
Because we don't control when you set particular properties, we have the unenviable task of ensuring that all interelated properties update each other. This is done once per-frame and what we didn't want to do was recalculate all this stuff everytime anyone changed a particular value. This would mean during the standard configuration of a T2D object, several recalculations would take place and we didn't want to expose some kind of nasty "calculate()" function or anything that you'd have to remember to call.
David Myers found a similar problem during the beta-testing and we came to a compromise which was that we still only calculated this stuff once per-frame but within the console commands that set key properties, we'd calculate the specific related settings only.
We had an identical problem with the "mount()" command and it was an oversight on my part that I didn't apply the same container-update call in the add link. I've just fixed that and so expect it to work in the next update.
Thanks for the info!
- Melv.
03/06/2005 (2:55 am)
@Ben: This is indeed a problem but has now been fixed.Because we don't control when you set particular properties, we have the unenviable task of ensuring that all interelated properties update each other. This is done once per-frame and what we didn't want to do was recalculate all this stuff everytime anyone changed a particular value. This would mean during the standard configuration of a T2D object, several recalculations would take place and we didn't want to expose some kind of nasty "calculate()" function or anything that you'd have to remember to call.
David Myers found a similar problem during the beta-testing and we came to a compromise which was that we still only calculated this stuff once per-frame but within the console commands that set key properties, we'd calculate the specific related settings only.
We had an identical problem with the "mount()" command and it was an oversight on my part that I didn't apply the same container-update call in the add link. I've just fixed that and so expect it to work in the next update.
Thanks for the info!
- Melv.
#8
Judging by the dates on these posts, I'd say an update is probably just around the corner.
07/03/2005 (12:09 pm)
Version 1.02 has this problem. It took me forever to figure out the correct order and what objects I need to assign to. So heads up for anyone in a similar ship: setsize() before setting the linkpoint.Judging by the dates on these posts, I'd say an update is probably just around the corner.
#9
T2D doesn't have this problem actually, it was fixed. The problem is that after fixing the problem, further development broke it, something to which I am humbly ashamed of. ;)
What was wrong though was the fact that a secondary parameter added into the physics wasn't being initialised until the size was set whereas the previous problem was that the spatial-container stuff wasn't being updated from script-calls whereas it was from within the engine itself each loop iteration. This problem is due to the "mHalfSize" member of the fxPhysics2D class and I posted a quick fix here for it.
This has most definately been fixed! ... I think. ;)
- Melv.
07/04/2005 (4:37 am)
@Eric,T2D doesn't have this problem actually, it was fixed. The problem is that after fixing the problem, further development broke it, something to which I am humbly ashamed of. ;)
What was wrong though was the fact that a secondary parameter added into the physics wasn't being initialised until the size was set whereas the previous problem was that the spatial-container stuff wasn't being updated from script-calls whereas it was from within the engine itself each loop iteration. This problem is due to the "mHalfSize" member of the fxPhysics2D class and I posted a quick fix here for it.
This has most definately been fixed! ... I think. ;)
- Melv.
Torque Owner Harold "LabRat" Brown
You use the local world coordinates of the object to define the linkpoint... -1->0-> 1 / -1->0->1 and your call on creation looks fine also.