How to Position Bones

Attention Topic was automatically imported from the old Question2Answer platform.

Hi everybody, i’ve been trying to make a decent tank game for sometime and i’m getting somewhere, but i have a problem, i made a tank and rigged it’s tracks believing i could make so the position of the bone is equal to the position of the tank wheel (or the other way around, dunno), it’s a cheap way of getting tracks to work like in a tank, but i’m struggling to make it work, here’s what i got:

``````func _process(delta):
for LB in 5:
var t = \$Armature/Skeleton.get_bone_custom_pose(LB)
t.origin.y = LWS[LB].global_transform.origin.y
\$Armature/Skeleton.set_bone_custom_pose(LB, t)
for RB in 5:
var t = \$Armature/Skeleton.get_bone_custom_pose(RB)
t.origin.y = RWS[RB].global_transform.origin.y
\$Armature/Skeleton.set_bone_pose(RB, t)
``````

basically it should work, the tank has 5 wheels on each side, and the track has an skeleton with bones for each of the wheels on each side, weight painted to move only their part of the tracks, but i’m lacking the logic so it could function properly, LWS and RWS are arrays with all of the VehicleWheels of the tank, LWS is for the left side and RWS for the right side, and i use them to move the tank by adding power directly to the wheels (so i can neutral steer and manouveer like a tank does), but how can i achieve what i’m looking for?

Thanks in advance for any help!

Well i think i’m probably “the” dumbest person on earth, of course it would not work properly if i was getting and setting the wrong bones, so an update to the code:

``````func _process(delta):
for LB in 5:
var t = \$Armature/Skeleton.get_bone_custom_pose(LTB[LB])
t.origin.y = LWS[LB].global_transform.origin.y
\$Armature/Skeleton.set_bone_custom_pose(LTB[LB], t)

for RB in 5:
var t = \$Armature/Skeleton.get_bone_custom_pose(RTB[RB])
t.origin.y = RWS[RB].global_transform.origin.y
\$Armature/Skeleton.set_bone_custom_pose(RTB[RB], t)
``````

before this i was getting and setting only the first 5 bones in the skeleton, now i made another two int arrays and i’m using those to get the correct bones (i know it isn’t the most modular way of doing it but for now it just works), but i still got the position problem to fix because now the bones stand higher than the wheels if i drive it uphill and lower if i drive downhill (or the other way around), i don’t really know why, i think there’s something to do with how i apply the position to the bones, dunno. I will try i little more, see if there is some logic i’m missing, any help will be appreciated.

StrikerSVX | 2021-08-04 02:02

Well, it looks like i fixed my problem myself, probably not the best solution but it works for now:

``````func _process(_delta):
for LB in 5:
var t = \$Armature/Skeleton.get_bone_rest(LTB[LB])
t.origin.y = -LWS[LB].transform.origin.y
\$Armature/Skeleton.set_bone_rest(LTB[LB], t)

for RB in 5:
var t = \$Armature/Skeleton.get_bone_rest(RTB[RB])
t.origin.y = -RWS[RB].transform.origin.y
\$Armature/Skeleton.set_bone_rest(RTB[RB], t)
``````

So trying to make it work with global_transform wasn’t helping much, and by getting the resting position of the bones instead of just the normal position i could fix the tracks going higher or lower than the wheels.