I don’t have time to make a mouselooked example, but you’re capable with python, so you can probably figure this out. Holding the WKEY will pickup the object, and releasing drops it (paste this into the Script.py in the blend i posted, and delete the other scripts).
So, you can use a ray sensor looking for objects with a property pickup, and if that is true and you press P for pickup, it sets a property to true; and that is checked by the script and runs the code.
when you press p again it drops object by not running code.
import bge
def moveObject(object_move, object_target, speed, gravity=False):
'''Moves an object at a gradual rate toward target
:param object_move: the object to move
:param object_target: the object to target
:param speed: the speed of movement
:param gravity: to enable effect of gravity on object
'''
if not object_move or not object_target:
return
if not gravity:
object_move.applyForce([0,0,9.81],0)
start = object_move.worldPosition
end = object_target.worldPosition
last = end - start
last += start
object_move.worldPosition += (last - object_move.worldPosition) * speed
target = bge.logic.getCurrentScene().objects['Empty']
pickup = bge.logic.getCurrentScene().objects['Sphere']
if bge.logic.keyboard.events[bge.events.WKEY]:
moveObject(pickup, target, 0.4)