6

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. :)

admbro
  • 333
  • 3
  • 14
  • 3
    maybe use a trick like a second ball? – moonboots Jun 25 '22 at 07:20
  • thank you moonboots for the suggestion. I would like to have it controlled by the simulation. Maybe it's more of coding question? I wish i had a better way to articulate. – admbro Jun 25 '22 at 22:25
  • 1
    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. – Chris Jun 27 '22 at 08:28
  • 1
    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. – vklidu Jun 27 '22 at 09:51
  • @vklidu I tried answering the question using physics... Strangely, since a few blender version updates, the developers have stopped updating physics. I tried animating dynamic, animated values but ------ It went haywire, falling down and then suddenly blasting up at the speed of light. Of course, we could use a second ball like moonboots said, but not always the ideal solution. – Yousuf Chaudhry Jun 27 '22 at 10:09
  • @vklidu Maybe geometry nodes could work... Make sphere go to the 2nd portal, then switch off animated (considering it was already animated to be on) and then maybe it would work. – Yousuf Chaudhry Jun 27 '22 at 10:12
  • thank you very much for the information. I appreciate the thoughts on how to solve. :) – admbro Jun 29 '22 at 17:59
  • 3
    as you can think of, even teleporting takes some time ... ;) and so this might be a solution: [1]: https://i.stack.imgur.com/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" ;) – Chris Jun 30 '22 at 08:46
  • 2
    @Chris. Thank you. I think that's a great work around. – admbro Jul 01 '22 at 12:03

1 Answers1

1

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

Chris
  • 59,454
  • 6
  • 30
  • 84