object flies to another object

How would I make an object go to another object. EX. there is a line going from the crosshair and when an object gets within .2 distance away from it, the object goes to a hand. Kind of like call of duty’s method.

You need to use a Python script to do stuff like that.
Split your Blender 3D View window into two and set the second window as a Text Editor. Click “New”. Add a Near sensor and a Python controller to your crosshair, no actuators. Set the Python script to “Text”, and paste this in the text editor:

cont = bge.logic.getCurrentController()
own = cont.owner
obl = bge.logic.getCurrentScene().objects
sen = cont.sensors

if sen['NameOfNearSensorAttachedToScript'].hitObject == obl['NameOfItemObject']:
    obl['NameOfItemObject'].worldPosition = obl['NameOfPlayerHand'].worldPosition

Note that this is a very, VERY simple and rudimentary way to do it. But it can be tweaked and enhanced as you get more and more used to how Blender and Python work.

This is assuming that the crosshair is in the same scene as the main game character; if it’s in an overlay scene, then the near sensor won’t be able to pick anything up. Michelle’s method would work also with an invisible object (or the camera).

Thanks all :smiley:

haha I KNEW I forgot to mention something! Thanks for clarifying.

do you want it to float over or snap?

snap. .

Here you go,

this is for a unique combo,

like object 1 is close enough -> object 2 (snap)

not

object 1 is close enough to any Object X -> snap to closest

I can set it up to cast rays @ the closest target, but you need to let me know if that is what your looking for,

Attachments

OSNAP.blend (448 KB)