Could somebody provide me with a python blend file where an object attaches itself to another, one object would move to intercept another, so therefore that object remains attached to it.
I had tried this using the bricks a few months back, but I didn’t get anywhere with it, so I’d thought I’d inquire about this being the final solution. The alternative was to try and use Unreal engine, as there would be plenty of tutorials of course that wouldn’t be python or any bricks.
Yes, I tried this with the bricks, one object collides with another, and then the other object is suppose to load in, parented onto the moving object. So therefore the illusion that the object moving was the same, when the new one is loaded in from another layer.
Due to it’s dynamical behavior (getting the object collided with) you will need Python code to do that.
import bge
SENSOR_COLLISION = "Collision"
controller = bge.logic.getCurrentController()
if all(sensor.positive for sensor in controller.sensors):
collisionSensor = controller.sensors[SENSOR_COLLISION]
thisObject = controller.owner
collidedObject = collisionSensor.hitObject
collidedObject.setParent(thisObject)
You need at least one collision sensor named as in the above code (“Collision”). When the objects collide the object with this logic will parent the other object to itself.
The above code does not do anything with path finding, path following. This was not requested.
The object the colliding object should stick to.
collision sensor –> Python (above code)
This will make any object detected by the collision sensor being parented to the object with that logic. it will act like covered in super glue.
To avoid getting all objects of the scene I suggest to filter them by setting the property field of the collision sensor. E.g. only objects with property “sticky” will stick.
No.
You need to ensure the collision can be registered by the collision sensor.
Hmm, okay so no boxes then. As for the object no the direction it travels is fine, so no problem. As for a second or third, hmm, may be some kind of modified code may be necessary.
As for the code itself, I guess remove the bricks except for collision and add the python code.
I don’t know, the code just makes it all confusing. Does the property go on the skeleton or the object? What does the code need, an object?