Kayl Posted November 8, 2010 Share Posted November 8, 2010 Hi there, I'm trying to play a bit with bones. I'm trying to "attach" an object relatively to a bone. The first problem concerns the position of the bone (here, a bone in the head). It appears that, in order to have the object following the bone smoothly, the getBonePosition + setElementPosition (on the object) must be done onClientPreRender. However, when walking on steep slopes, it seems GTA changes the bone position between onClientPreRender and onClientRender, I guess it's a result of inverse kinematics being performed to make the ped's feet touch the ground and adapt the current animation accordingly. In this case then the valid position is the position given onClientRender but if I set the position of the object onClientRender, the position is fine, but the object is flickering. Whereas if I set it onClientPreRender, the object doesn't flicker but isn't in the right position when it comes to peds walking on non flat ground. Illustration code: addCommandHandler("bone", function() local objectPreRender = createObject(2054, 0, 0, 0) local objectRender = createObject(2054, 0, 0, 0) local objectRender2 = createObject(2054, 0, 0, 0) local bx, by, bz = nil, nil, nil addEventHandler("onClientPreRender", getRootElement(), function() bx, by, bz = objectToBone(objectPreRender, 0, tocolor(255, 0, 0, 255)) end) addEventHandler("onClientRender", getRootElement(), function() objectToBone(objectRender, 0.1, tocolor(0, 255, 0, 255), objectRender2, 0.2, tocolor(0, 0, 255, 255), bx, by, bz) end) end) function objectToBone(object1, offset1, color1, object2, offset2, color2, bx, by, bz) local newbx, newby, newbz = getPedBonePosition(getLocalPlayer(), 5) setElementPosition(object1, newbx, newby, newbz + offset1) _FDP({newbx, newby, newbz + offset1}, color1) if object2 and bx and by and bz then setElementPosition(object2, bx, by, bz + offset2) _FDP({bx, by, bz + offset2}, color2) end return newbx, newby, newbz end function _FDL(sx, sy, sz, ex, ey, ez, color) local realColor = color or tocolor(255, 0, 0, 255) local ssx, ssy = getScreenFromWorldPosition(sx, sy, sz) local esx, esy = getScreenFromWorldPosition(ex, ey, ez) if ssx and ssy and esx and esy then dxDrawLine(ssx, ssy, esx, esy, realColor, 2) end end function _FDP(pos, color) local delta = 0.1 local x, y, z = unpack(pos) _FDL(x +delta, y, z, x-delta, y, z, color) _FDL(x, y+delta, z, x, y-delta, z, color) _FDL(x, y, z+delta, x, y, z-delta, color) end And the result (Z offset is on purpose to differentiate techniques): Is there any way to solve this dilemma? The second issue I have is different and not as important for now and is more a feature request. It's about the orientation of a bone. Looking at MTA's code, it seems there isn't yet the ability to extract (from GTA) the absolute orientation of a bone (only its position). Hence it becomes quite tricky to attach an object to a bone without it. However, luckily for me, the head has several bones that barely move with respect to one another (I guess only for "facial" animation). So I'm able to derive an estimate of the bone orientation I want. If by any chance, at some point in the future, one dude responsible for finding available functions via Reverse Engineering had some time to look at that and provide us with a getPedBoneMatrix() that would be epic (But don't worry I'm aware there are more important things to work on at the moment). Link to comment
12p Posted November 9, 2010 Share Posted November 9, 2010 maybe you can use setObjectRotation and getPedRotation, it may solve your orientation problem Link to comment
Xierra Posted November 9, 2010 Share Posted November 9, 2010 Woo, advanced scripting techniques... What are you making this for? Accessories like hats or something? Just curious of your intention... Link to comment
Kayl Posted November 9, 2010 Author Share Posted November 9, 2010 XX3 > Indeed the end goal is to be able to attach object like hats or other items to a ped. Both problems need to be resolved to be able to do that correctly (for the orientation one, the hack I currently do in the head only works for some skins, providing the orientation of any bone would allow me to make it work for all). benxamix2 > I don't want to attach the object to the root bone of the ped but to a specific bone which, during animations, changes offset and orientation. But as I mentioned, this topic is more about the positioning than the rotation (which can be hacked for most skins when it comes to the head). I didn't put my rotation hack in the example code since I want to focus on the position issue first. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now