Question: Scripted TrackTo (only per Script) is that possible?

Hi all,

I’ve a perhaps not easy question: Is it possible to realize a trackTo per script, where the x-axis is up and the z-axis is tracking to an object?

I need exactly that per script for a try out of a game-play.
I’ve make an undone testing file, for first the testing of the right arm, only.

reduced_test_file_rotation_check_190b6.blend.zip (319 KB)

I tried to work with getVectTo() and alignAxisToVect(), but it didn’t worked realy.

Short to what I want and the reasons:

I want to control the arms with the mouse, exactly right mouse button for the right arm, left mouse button for the left arm.
The movements control the direction - important for 3D movements:

More or less exactly horizontal: it should control the forward/backward direction. This I think is the best way to control it for forward and backward.

Rather vertically: Up and down including to the sides.

For good movements I can’t need “funny” rotations of the angles, which are automatically calculated for inverse kinematics.
I need to control the orientation of the IK-solver with the empty, this depends on calculated angles for the orientation.
The problem is there, that I need the trackTo the schoulder and the angle of the triangle hand angle and the distances to Ellbow and Schoulder. Actually I’m trying to get the z-axis later comes the y-axis added to it.

Kind regards,
Arne Burkandt.

ok, I want to help, but there is too much words, and not enough information,

can you draw a series of pictures or a video?

I think you are talking about mixing mouse Look and Ik,

I have done this in the past, by using 2 empties (or more)

Base Rot = parented to base bone

Desired Rot = parented to base rot.

aiming bone = parented to base bone, uses copy rotation or IK to track to Desired Rot object.


rot = Base_Rot.worldOrientation.to_euler()
rot.x += (mouseLookOffset)
Desired_Rot.worldOrientation = rot

look up ‘Simple mouse’ in resources for a mouse offset calculator object.

This should probably work for something like a cannon, where the object rotates on the x-axis and aims with the y-axis.

import bge, math

scene = bge.logic.getCurrentScene()
cont = bge.logic.getCurrentController()


# objects
own = cont.owner
cursor = scene.objects["Tracker"]


target = cursor


vec = own.getVectTo(target)[1]
own.alignAxisToVect(vec, 1, 0.1) # write


# maximum and minimum lean, converted from degrees to radians
xMax = math.radians(own["Max"])
xMin = math.radians(own["Min"])


x, y, z = own.localOrientation.to_euler()
x = min(max(x, xMin), xMax)
y = 0.0
z = 0.0
own.localOrientation = [x,y,z] # overwrite

It should be easy to change the aim axis

#edit double post… read the one below.

and another trackTo:
pass it: obj = the object that needs to trackto something and a vector where you need to track to (like orientation or position or a combo of both).


def face_direction(obj, vector):
    
    track_axis = 1 # x,y,z = 0,1,2
    turn_speed = 1.0 # 0.0 - 1.0
    
    # face direction
    obj.alignAxisToVect(vector, track_axis, turn_speed)
    # head up
    obj.alignAxisToVect([0.0,0.0,1.0], 2, 1.0)

oh dont forget to change the axis from the head up, first is z vector then up = 2 = z axis, 1.0 = turn_speed

Ah thank you Cotaks,

I will try it out in the evening.

@BluePrintRandom: Um, no, it’s more about control the IK of the arm in the 3 axes per mouse. Maybe a Picture shows better what the mouse movements should effect that:


Think by the arrows and lines on the right mouse-button, while you move the mouse.

It’s not the complete game play, but a 1st step, okay but I don’t have any further pictures about what I want to the hand. So I want to draw them after work, for upload them later.

Kind regards,
Arne.

are you trying to use mouse angle to select an animation and set Ik position?

again, I would say check out my mouse offset system, and use it to move the IK target object local to a core


from mathutils import Vector
IK_target_object.worldPosition= (avatar.worldPosition+(avatar.worldOrientation*Vector([X,Y,Z]))

here you use a mouse axis value to offset X,Y, or Z based on gesture and key commands.

the same values (mouseOffsets) x, and y could select animations for pole targets, or shoulder bones etc.
or even ‘control states’ for setting the pole target with code.

Your request is less a track to (which means it points to a specific point/object in space tracking it over time). It is more a how to move/turn bones according to mouse movement.

The tracking make sense when you move an object by mouse and the bones should track that object.

What exactly are you aiming for? “Turn bones via mouse movement” or “move object and bones track to that object”?

Um, rather move and turn an empty, which is the IK-ruler for the bones. The above drawn arrows on an old screen shot should give the directions of the movements.
The turning of the empty has to be calculated from two triangles consist out of an empty in the shoulder. One of the help empties is at the shoulder hight over or under the hand angle, the other over or under the elbow (every at the height of the shoulder).
I think this picture I’ve drawn explains very good what I want:


The turquoise color represents the help empty at the elbow.
The empty controls the end of the IK chain, actually without the rotations, that I want to activate if the empty rotates correctly.
If there are informations about what I want are missing, feel free to ask for the informations. Then I will give them.

AT Cotaks: Thank you, with this information (script-code) I think to came further.

And before I forget it: Sorry for my misleading phrasing, I was not complete clear in my head.

Kind Regards,
Arne.

I still do not know if you want to turn the arm with mouse or if your want to let the arm point to a specific object.

Okay, I want to move an empty which rules the ik of the arm, so far so good. The empty is the ik-ruler of the lower arm, the lower arm currently depends on the position of the IK-ruler empty, only. That is why you can accept the latter.
But, the rotations of the IK-ruler should take the calculated turns in the direction which shows along the axes of the lower arm as IK-solver. I want to realize that.
Then I can let the IK-ruler specify the rotations of the IK-solver, in our case the lower arm.

I ask this because you restrict yourself to IK resolvers. This is not necessary when you just want to turn the arm via mouse movement (mouse moves left arm moves left too).

You would not even nee it when you have a formula that calculates action frames to coordinates (e.g. when playing two arm turn actions one up/down one left/right).

You will need it when the hand changes distance (e.g. for grabbing).

Well, the distance changes often and I used the IK because the full control over the position of the hand, too.

Example:
If you later in the game want to grab the sword, then I thought that you only need to press the right mouse button, move the mouse a short part to right (for forward) and then to left down. Then after grab the belly around, move the mouse a short piece backward, to come to the handle of the sword.
Pressing the key f would activate the grab/release of the hand for which you are pressing the mouse button.

I don’t know to give this control per actions, may be I just do not have enough imagination to imagine how this should go. That I don’t know. I don’t know to realize that with actions. So I want to use IK resolvers. A few parts of the game play I need to think about it are missing, that I agree.

Regards Arne.

Known start and end poses
This is an example where an action is most efficient. The start and end poses are known beforehand. The number of swords that should be grabbed differently should be pretty limited. It is more or less the end pose of the hand.

A little bit more complex can be the animation how to draw the sword as the sword geometry has major influence on that. Again, there shouldn’t be that much animations necessary but maybe more than the previous animation (placing the hand on the sword).

The big benefit is it can look very plausible as you have can even motion capture the animation. Another one … it is just plying the action. no fancy logic necessary.

Dynamic end pose
A different situation is when the sword is laying on a table. The character can stand somewhere near the table. Even that can be done with a predefined grabbing animation. Let the character walk/turn into a known position -> back to Known start and end poses.
This shouldn’t be a big deal as the area from where a character can pick things should be limited (a question of how you design the level).

If that is not possible e.g. you want to to point the hand (or sword tip) to any (of many) position in the scene e.g. object under mouse cursor). In that case an IK-resolver can help. As far as I remember the IK-constraint targets work on bones only (you need to check). The easy solution is to place that bone to the desired position. I think you do that with Python. You convert the target object position (in scene space) to a position in the armatures object space (world to local space).

You might need to add more constraints to the armature to prevent unwanted poses (as there are some limits joints of a human body :wink: ).

Here is a demo how you can use objects as “late IK-target”.

It is based on a demo for some other purposes. Basically you can press a button to let the little red alien materialize an apple (yes, it is a really mighty alien). The Alien will drop the apple when you click the other button.


The interesting implementation for you is that the alien looks to the apples or the camera (when there is no apple to look at and the alien gets bored).

The file was created with 2.77a. For some reason Blender 2.78a crashes when starting the BGE (must be a problem with the armature). This gives you the chance to extract the technology from the file into your brain and use the fresh skills on your project :D).

Attachments

Aliens_Tell_looking.blend (244 KB)

Thank you, I will take a look on it today.

Off topic: Sorry that I response so late, but I had problems in the real live.

On topic again: If I have some questions about the file, I will post it here.

Kind Regards,

Arne.