Make object A go through object B


(blenderaptor) #1

Hi guys,

What im currently doing : using python to parameter a Motion Actuator. I work on a PLAN (so i rotate on Z)

What i can do now : make object A face B then , gravitate around B and still face B. For that i just use the arc tangente and the nice getVectTo() function. I just use the distance (“cc” ) between the 2 objects so i get how much i have to rotate A to face B at each frame while localy moving A on it’s own local X axis (lets say : 0,03 unit at each frame). That’s ok, just have to parameter once (not re-calculated each frame)

    vec = obj_A.getVectTo(obj_B)
    cc = vect[0]
    
    mot.dLoc = [0.03,0.00,0.00]
    mot.dRot = [0,0,atan(mot.dLoc[0]/cc)]

–> BUT

What i’m looking for : A (the red cone) is not 100% facing B (thin cylinder at 0,0) , B is just somewhere in front of A. I want to move A on its local +Y axis (let’s say 0.03 per frame) but i want to rotate A on Z in such an amount it goes through B (so 0,0) after x frame

Does anybody knows how i can derivate the amount of Z (here, clockwise) to rotate at each frame ? It’s a bit like golf ball finding the hole


(- Click for resources) #2

if you do:

cone.alignAxisToVect([0,0,0], 1, 1.0)

[0,0,0] is the vector to align to, obj.worldPosition works as well, 1 is the axis that needs to point to it (y in this case) and 1.0 is the turn/align speed. Now it always aligns/point to it perfectly.

you already have the code to go around it?
so now you can just set the/any z or x speed?

cone.localLinearVelocity.z = 0.03

or do i not understand it correctly?


(blenderaptor) #3

thx for answering.

Yes, i know this function but it’s just about rotating. And it’s first parameter is a vector and not a point (if i remember well) . There’s is the lerp function dealing also the distance with also the possibility to variate [0,1]

https://docs.blender.org/api/current/mathutils.html?highlight=lerp#mathutils.Vector.lerp

I was just wondering if it was possible to set values once . Because , ofc, i can go full crazy pulse mode and do something like

cone.alignAxisToVect(vec[1], 1, 0.1)

And it will align very quickly, but also, not in a linear way . And, as i said, i prefer to avoid to recalculate at each frame ; like a game of golf … once the ball is launched, its too late to re-ajustate.

On the other hand, i have yet no idea about how works all that “velocity” and “torque” stuff :stuck_out_tongue: Do you think it could help me to set my motion Actuator correctly ?


(- Click for resources) #4

yes first point is a vector, so is position, orientation, etc.
so if you would have a center object you can do this:

    center_vector = own.scene.objects['center_point'].worldPosition - own.worldPosition  
    own.alignAxisToVect(center_vector, 1, 1.0)

so it aligns to it, this indeed needs true pulse

velocity is the real speed. so by setting it’s velocity you move the object (without teleporting) on any axis you like. so then you do not have the need for motion bricks.


(blenderaptor) #5

do you mean that if I python this in my code

cone.localLinearVelocity.z = 0.01

it will take 100 frames instead of 1 to do what Cone is expected to do on it’s local z axis ?


(- Click for resources) #6

it will move the object by 0.01 unit/meter a step


(blenderaptor) #7

ok, i hope it will influence also the Motion bricks because i like to use some bricks to structure my program


(- Click for resources) #8

it will not influence the brick but the object, also @edderkop is way better with this kind of math then me, but you want it with bricks, so that creates a little problem(he solved a big orientation issue for me last year).

Do you have a demo file?
I recreated yours but i’m only getting strange results so i wonder how you got it to work in first place

At least i know that you want to let the cone spiral downwards trough the torus but with bricks i have no clue.


(Monster) #9

I suggest to do this approach:

  • check what direction to turn

  • check if the difference between the current and the wanted orientation is larger then a maximum single step (turn)

    • if larger: perform a maximum step
    • if smaller or equal: set the wanted orientation (= a partial step)

This needs to run at each single time the object should perform a step (otehrwise you get just one step and thats all).

Options:
You turning vertical and horizontal independently. This is a bit simpler, but does go the shortest way.


(blenderaptor) #10

Unfortunately, i just built it for the showcase. Don’t forget that motion actuator has to be on Local (loc and rot) and A has to be already facing B. Also, dLoc[0] needs a value you can choose. Double check the value of “distance” (same plane, no Z delta)

My previously question is precisely to get , in the first place, the A facing B. But i want to ‘mathematicaly’ derivate the orientation A has to + or - localy at each frame.

A bit like a comet, it goes straight to a planet then start to gravitate around and face it. I can only made the second part.


(blenderaptor) #11

I draw it because, people will be lost in all the text

A has to end on B with it’s local Y axe (green) facing B (i didnt say same orientation) . In the drawning, i show the trajectory in 3 steps (frames) but, ofc, the more steps, the more the trajectory will be similar to the circle

exemple

The center of the circle is NOT necessarly in the midway of (A,B) . The more A is facing outwards B, the bigger will be the path joining them (coz bigger angular distance)

Ofc, its more complicate than simply splitting the world Position’s and world Orientation’s Deltas by the number of step/frames. I think that anyone who studied maths at University has the formula