BGE moving objects in game (help)

Hey guys so im working on the basics of game at the moment. don’t know anything about python was wondering if anyone had a script or tutorial to help me out. I need to run up to this ‘CUBE’ and when i’m near it, the ‘CUBE’ will travel down an axis away from me (or in a direction I choose) but when I move away from the ‘CUBE’ it will move back to its original location. I used some logic editing to make the ‘CUBE’ move away from me (using the near sensor) but I cannot get it to move back to is original location. any help would be greatly appreciated.

Hi!
i read about your idea, and tried to bring it in python. But i am a newcomer as well. It did not work out, i get an error.
I am not sure about if i should post my stuff here, but if it is 100% crap, the big guys of blender game will tell us.

I thought about using python to get the actual world position of the object, to get the defined original position and to get the distance to the player.
If the player is near, nothing will happen.
If it is far, the Object will get a force-push to move back to its original location.
I fear the syntax is wrong and i fear it is to simple and there are better ways, but here is my (fail)attempt.

before the code, i want to tell you what helped me:
Tutorials of python are everywhere to find, but partly they confused me, because of different Blender versions and different code-use. Blenders Evolution speed is good, but cause problems for learning sometimes.
I want to give you some Links to tutorials which i consider as helpful:

ok, heres the attempt:

import bge


def main():

    # get the scene
    cont = bge.logic.getCurrentController()
    own = cont.owner
    #scene
    scene = bge.logic.getCurrentScene()

  
    #search for 'players'. If only one player, it could be adressed directly.
    List = [s for s in scene.objects if 'player' in s]
    if List :
            print(List, "check, list exists")
    
#define the original position:
original_valuex = 0
original_valuey = 0
original_valuez = 0

cubeposition_x = own.worldPosition.x

#check if the player is near:
distance = own.getDistanceTo(playerList[0])
#check if the distance is enough to trigger the "back to origin behavior"
if distance >= 20:
    #check if values have changed / is not the original value
    if (cubeposition_x  - original_valuex) > 0:
        #move it on the x axis in negative direction
        # apply force to x axis 
        force = [ 20.0, 0.0, 0.0]
        # use local axis
        local = True
        # apply force
        own.applyForce(force, local)

    if (cubeposition_x  - original_valuex) < 0:
        #move it on the x axis in positive direction
        #apply force to x axis 
        force = [ -20.0, 0.0, 0.0]
        # use local axis
        local = True
        # apply force
        own.applyForce(force, local)
    
    
#...same with y and z positions.

   

main()


i got an error, that “own” is not defined.

Good Luck for your Solution!

Thanks for tips the links r already helping me under stand all this its making reading it easier for sure! :smiley: :smiley: thanks for the links!!!