6
$\begingroup$

Is there a way to "teleport" a rigid body when it comes in contact with some kind of trigger object?

enter image description here

attached a sample scene.

Edit: Perhaps this is a coding (python) question. logic would be if object makes contact with a trigger (another object) it is moved to an X,Y,Z coordinate in the world space. Unfortunately I do not have enough experience to know how to execute. Thank you very much.

I would like to have the balls fall into the 1st portal and then appear in the 2nd portal. I would like to have this driven by the simulation (if that makes sense). I can make this happen in unity by using a trigger that changes the object location. I am grateful for any help. Thank you for your time. :)

$\endgroup$
9
  • 3
    $\begingroup$ maybe use a trick like a second ball? $\endgroup$
    – moonboots
    Commented Jun 25, 2022 at 7:20
  • 1
    $\begingroup$ there is no way AFAIK to do this "just" by simulation/physics (or whatever you want to call it). You have to "turn off" the physics (check the animated checkbox) at a certain point to achieve this effect. So either you use a second ball as moonboots proposed, or use the "animated" checkbox or another hack. $\endgroup$
    – Chris
    Commented Jun 27, 2022 at 8:28
  • 1
    $\begingroup$ That is why OP add the bounty for a python solution :) ... it doesn't sounds impossible to me (someone without scripting skills :) ) ... if object reach second ring location (proximity) switch ON Animated, change location to first ring loc, switch anim OFF ... what I see as an issue - ball is speeding up in its trajectory, so you would have to cheat with some compromise of initial speed and direction to keep a feeling of portal continuity ... or OP would have to wait for Blenders Game Engine. $\endgroup$
    – vklidu
    Commented Jun 27, 2022 at 9:51
  • 3
    $\begingroup$ as you can think of, even teleporting takes some time ... ;) and so this might be a solution: [1]: i.sstatic.net/8FYJJ.gif i just gave it a try and of course my additional mechanic should be made invisible. If this would be a solution for you, let me know, then i will write an answer. It is indeed all done by physics with drivers. And a very bit of python. I just realized it for two balls...because i am lazy, so just forget about the third ball ;) and i am sure you could optimize it so the ball is even quicker "teleported" ;) $\endgroup$
    – Chris
    Commented Jun 30, 2022 at 8:46
  • 2
    $\begingroup$ @Chris. Thank you. I think that's a great work around. $\endgroup$
    – admbro
    Commented Jul 1, 2022 at 12:03

1 Answer 1

1
+50
$\begingroup$

Ok, here is my example (which of course could and should be improved, so it is "just" a proof of concept):

This is my python script:

import bpy


def funny1(obj):
    
    obj = bpy.context.scene.objects["ball1"]
    
    print(obj.matrix_world.translation)
    
    zLoc = obj.matrix_world.translation.z
    
    print("z is", zLoc)
    
    if zLoc < -10:
        return 6
    
    return 11


def funny2(obj):
    
    obj = bpy.context.scene.objects["ball2"]
    
    print(obj.matrix_world.translation)
    
    zLoc = obj.matrix_world.translation.z
    
    print("z is", zLoc)
    
    if zLoc < -10:
        return 6
    
    return 11


bpy.app.driver_namespace["funny1"] = funny1
bpy.app.driver_namespace["funny2"] = funny2  

All it does is set back the piston spring (pusher), if the ball is higher than a specific z-value. If it is lower than a specific value, it releases the pusher and the ball will be pushed.

So these driver functions i added to the y location of the pusher like this:

enter image description here

to execute the example file, first run the script, then update both drivers, then run the animation.

please be aware that i set the pushers on different rigid body collections so that they don't disturb each other:

enter image description here

enter image description here

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .