Make cube snap to position.

I have uploaded a .blend
How do i make the cube snap to the door, facing forward even if the cube is roated.
http://www.pasteall.org/blend/40253

It would greatly help me out, as i need my character to open doors, this would make
her stand in front of it perfect while it runs a animation.

You might need to put a plane in front of the door, with a property “Door”

Do you want the cube to move to the doors location or have the cube be rotated to face the door?

Yeah so it`s rotated properly and not in the door way, but facing the door on the -Y axis.


This is kind of what you want, pay attention to the track axis of the edit object and ray, make sure they are the same orientation as your cube :slight_smile: now this works for one door but you obviously want more than one door, so you have to workaround the fact that the track to actuator only tracks objects. you have two options

  1. python - use python to track via property
  2. logic - im imagining some kind of workaround where it tracks one box; ‘door’ that is invisible and what not, added ontop of the textured doors when the player is near, and deleted when the player is not. this way you can still only track to the one object that just gets jumped around the scene. this could get messy, let me know if you want help with the track via property i think i have a script somewhere

Yeah i tried edit object lol.
It definitely needs python for this one mate :slight_smile:

give the object u want ur character to snap to a property ( boom )



from bge import logic

def main():
cont = logic.getCurrentController()
own = cont.owner #your character
scene= logic.getCurrentScene()
obs = scene.objects

for i in obs:
if "boom" in i:
target = i

own.worldPosition[0]  = target.worldPosition[0] # assign xposition
own.worldPosition[1]  = target.worldPosition[1] # assign y position // adjust  it with plus  or minus a number
own.worldOrientation = target.worldOrientation #making ur object face to same direction / adjust it on your will


main()


I put python script on the player, and always sensor and it`s not doing nothing.

i wrote the script on this page, so u have to add some indent spaces by yourself.

Chaos, on the blend you gave me nothing would worked cause your ray was casting on -y and your cube is facing -x i got it to work with the image above

Heres your blend working, its because your cubes local orientation was different then worlds orientation CTRL-A --> apply rotation
Help.blend (476 KB)

Heres a track based on property blend
track_to_prop.blend (512 KB)

With the track too i need it so whatever angle it touches it will align straight.

Similar to rockys post, this will only set his rotation to that of the door.


import bge

scene = bge.logic.getCurrentScene()
cont = bge.logic.getCurrentController()
own = cont.own

eKey = cont.sensors['Keyboard']
ray = cont.sensors['Ray']

if ray.positive and \
    eKey.status == bge.logic.KX_INPUT_ACTIVE:
        #set orientation to that of the door
        own.worldOrientation = ray.hitObject.worldOrientation
        #set x and y, hers where it gets tricky depending on the orientation of the door
        own.worldPosition.x = ray.hitObject.worldPosition.x + 1
        own.worldPosition.y = ray.hitObject.worldPosition.y

check out rockys code for how to align the world position, coded in the forums so it may get some console errors

I tried correcting it, but i don`t know where to indent lol

every next line of " : " ( if … : , for … : )