Interpolation between two values? and other question.

Hi, How i can make a Interpolation between two values?(python)

I’m planning on using this on 2 things:

1)I make a grab system for my game, basically:
-A ray is used for get the Object, and store the name in a property
-If you press click, and is there a object in the property mentioned above:
-A varible used for get if you are grabbing a object is changed to True.
-Move the Object to a empty in front of the camera.
-Deactivate the ability to rotate the object(practically convert the physics of the object, from a rigid body to a dynamic)
-Create a constraint.

So, the system work good, but i want to make the transition “smooth”, between the position of the object to the position of the empty.

2)When an object is in the crosshairs, the crosshairs activate a animation that makes rotate from one side to the other, but when the animation stop i want to make the crosshairs obtain the default rotation, in a smooth manner.


The second question, How apply a force to a object, but using a axis of other object? I will use it for throw the grabbed object.

edited

Sorry but…bump…

So the aim is to move an object from an arbitrary location to an empty smoothly?

Vector math makes things really easy


target_obj = .....
empty_obj = .....

dist, global_vect, local_vect = target_obj.getVectTo(empty_obj)
move_vect = global_vect/2                            #Move half the distance each frame. Possibly 1/5 would be better? Play around a little
target_obj.applyMovement(move_vect, False)

Off the top of my head, I can’t remember if the vectors returned by getVectTo are normalized, so you may need to add:


move_vect.scale = dist/2

My script only execute 1 time when the clic is pressed, so i have problem implementing the code.

PD: I tried the script with other object and work very good!

How about this? Monster’s manic gadgets - the attractor

I like your gadget, I saw the code and the system for atract the object is basically @sdfgeoff what said.

Thanks to @Monster :cool:, now just i need the second answer …I think is similar to the solution of the first question, and i no have a clear idea of ​​which is a vector.

PD: Almost forgot this …how make a object rotate to a specific value smoothly?

Pretty similar as the code I posted above, just instead of using applyMovement, you can use alignAxisToVect(vect, axis, smothness=0.5).

I haven’t looked at monsters code, but there is probably a single line you can change somewhere.

Vectors are great, and make things a lot easier, have a read up on them sometime

I guess that’s for the rotation, i test and what do is align the object, but how apply the force to the object using an object axis of another object? i need to apply the force, but without align the object.

PD: thanks for the link, i have a more clear idea of what is a vector!

I’m afraid I’m not sure what question you are asking in that most recent post. Can you restate the question?

i can’t believe this but i got it! :cool:

Exploring for vect in the python api, i I found the getAxisVect()

Is very simple:


target_obj = objeto["target object"]
reference_obj = objeto["reference object"]
    
axis = reference_obj.getAxisVect([0.0, 0.0, -32.0])*2
    
target_obj.applyForce(axis*10, False)
#many multiplication Here ...

Gracias por la ayuda @sdfgeoff.

I was talking…uh…see the image of the post…

were 3 questions …Make a rotation and movement smoothly(those are 2…) and how apply a force to a object using a specfic axis of another object.

Anyway since all are resolved!