Game armature manual bone rotation and gradual property change.

I want to know how to do a sort of “Track to” Constraint on a bone to a target object in an armature in the game. Like, during the game, I want the head bone to look at a certain thing.
I would like to know that, and how to make the bone’s rotation limited where it’s facing. (like it not being able to turn completely around like an owl’s head. xD) As well as the bone’s rotation in facing something being able to override a rotation set to it by an ongoing action. (Completely override or just add onto, either way works, but I’d prefer a complete override.)
Manual Bone Rotation.blend (499 KB)34[/ATTACH]

I’d also like to know if there is a way in python to make a gradual Property Change? Like, if I want property ‘Life gauge’ to change from 1 to 13, I want it to sort of count up from 1 to 13 in a brief period of time just to make it look smooth. Sort of like blendin from one action to another, except for a property.

Thanks in advance! :smiley:

Hi! For the first question: I’m not familiar with armatures but it seems that bones constraints work in bge:

  • The head is parented to the bone
  • The bone has 2 constraints: copy rotation of the empty and limit rotation in worldspace
  • The empty tracks to the target
  • You can move the target with ZSQD keys

EDIT: OOps… I haven’t seen that’s there is a track to constraint in bones constraints. No need to an empty.

For the second question:

import bge
cont = bge.logic.getCurrentController()
own = cont.owner

if own["gaugeValue"] < 13:

    own["gaugeValue"] += 0.001

simple code (adds 0.001 each frame while the “gaugeValue” property < 13) to be adapted… You can also use a timer or time module or use animations (I did not look at your .blend. Sorry if I misanderstood your questions)

Thanks a Bunch youle! :smiley: This helped me lots!

So I’ve encountered a Problem, your code doesn’t seem to really be compatible with any other stuff I try to add to it, like and if, or other requirements for a sensor to go off and such, I’ve attatched a .blend!

Color Change.blend (496 KB)

Hello! I’m not sure about what you are trying to achieve, but this example could help you:

(lerp function interpolates beetween 2 Vectors > So you can use it to mix colors (you first need to transform colors in mathutils.Vector type)

A more simple solution would be to use material animations (available since 2.74.5 version)

Tell me if you need more explainations about the code I made.

Yes! This is what I wanted! Thanks again youle! :smiley: