Game Development Community

Linkpoints

by Jonathon Stevens · in Torque X 2D · 01/17/2007 (6:50 pm) · 11 replies

I'm using a linkpoint to try to initiate the location of a bullet being fired from a rifle. I use the following code:

_player.LinkPoints.GetLinkPoint("barrelPoint", out bombLocation, out bombRotation);

It appears that it's placing the bullet as if the RIFLE itself's center was 0,0. Is this the intended course of action? I can't have a linkpoint point me to a spot on the screen, but just tell me how far form the center of the barrel i am?

EDIT: It's not even calculating properly from the 0,0 of the image either. The linkpoint is much farther away than it's returning that it is!

About the author

With a few casual games under his belt as CEO of Last Straw Productions, Jonathon created the increasingly popular Indie MMO Game Developers Conference.


#1
01/17/2007 (9:12 pm)
Remember that link points are in object space, not world space. Could that be it? So if your gun is 20x20 and the link point is at 3.0x0.0 then it will be 30 pixels left of the center of the gun.

#2
01/17/2007 (9:24 pm)
This is what I'm doing to set the location of the actual bullet:

_player.LinkPoints.GetLinkPoint("barrelPoint", out bombLocation, out bombRotation);

            bomb.Position = _player.Position + bombLocation;
            bomb.Rotation = _player.Rotation + bombRotation;

As you can see, I'm taking the origin of the player and adding the bombLocation to it which is the offset of the linkpoint from the origin of the player. Shouldn't that work? Maybe TGBX isn't working properly and showing the location of the linkpoint in the wrong spot?

#3
01/17/2007 (10:54 pm)
What values is the bombLocation vector being populated with and what are you expecting it to be populated with? A couple reasons I could see that code failing. Maybe bombLocation is the world space of the link point? Maybe bombLocation is the object space of that link point? Both of those cases cause your code to fail. If bombLocation is the world-centric offset of the link point, then your code succeeds. Since your code is not succeeding, I'm guessing it may not be the world-centric offset ;)

#4
01/18/2007 (6:24 am)
Shouldn't I be getting the world-centric offset from the linkpoint with the code above? There's no other way to get the linkpoint location other than what I've pasted above. Since TGBX doesn't show me coords at all, I'm not sure exactly what coords I should be getting. I do know that based on what I know to be coords in teh system, it appears to be reporting the linkpoint in the correct location on the gun, but when I add the player's location to the offset, it isn't working and instead is extremely close to the origin of the gun.

#5
01/18/2007 (8:31 am)
What is it returning, in numbers? It really sounds to me like it is the object space offset of the object. That's why it would be so close to the origin of the gun, because object space coords are so small (relatively).

#6
01/18/2007 (10:03 am)
Strange, I thought I pasted them. Will get them up shortly. Off the top of my head they were like -.8, -.5.

[gge_user=Jonathon Stevens
#7
01/18/2007 (5:18 pm)
Yeah, those are in object space. That's why they're so close to the center of the gun when you try to use them as world space coordinates. Off the top of my head I can't remember what the TX functions are for converting between object space and world space. They should be easy to find. Post if you can't find them and I'll look tonight when I get home.

#8
01/18/2007 (7:09 pm)
I looked into the GetMountPosition code and it's converting from mount space to object space to world space. I'm curious as to why linkpoints aren't converted to world space in the 'getlinkpoint' method?

I can't find any method that converts from object space to world space. What I found in the GetMountPosition file that said it was converting from object to world space simply added the coords of the mountpoint to the coords of the object being mounted to.

#9
01/18/2007 (9:01 pm)
Ok, what you're looking for are several overloads on T2DSceneObject for the method GetWorldLinkPosition. That will convert from object space to world space for you.

#10
01/18/2007 (9:55 pm)
I decided to roll my own code to figure out where to fire from and it's working now (based on the velocity, rotation, and position of the weapon) since it was faster dev wise.

I did look for GetWorldLinkPosition for future reference however and a search on that through the engine code came up with nothing? Are you sure that's spelled correctly? What file is it in? I can't see it in T2DSceneObject anywhere.

#11
01/19/2007 (1:00 am)
Oh, sorry. Maybe that won't be in until RC1. My bad!