Move to preselected location/rotation

Hi all. I’m setting up a demo in the game engine, and I’d like my character to move through a list of set locations each time a key is pressed.

For example, [spacebar]>move to [0,1,2], [spacebar]>move to [10,4,2], [spacebar]>move to [10,8,2], [spacebar]>move back to [0,1,2].
Ideally, I’d be able to move backward through the list of positions with a different key, but that’s a secondary goal.

I thought maybe I could do this with animation keyframes, but while I can play an animation, I don’t know how to just set the location to that of a single keyframe.

My next thought was to place empties at each location I want, and then copy the location of the empty into own.worldPosition. I suppose I could do that with python, but my guess is that there’s an easier solution.

Doesn’t matter to me if the character transports to the new location, or moves through gradually. Is it possible to do this with logic bricks? Seems like it might be, but I’ll do it in python if needed. Either way, I could use some direction. Thanks.

You can, in fact, do this with animation key frames. Instead of the standard “play” option for the action actuator use “property”. Then add a game property to your object, add a couple of keyboard sensors, one will add 1 to the property, and the other will subtract 1. Add two property sensors, one of them will check to see if the property is less than 0 (or the lowest frame in your animation). If so it should set the property to your highest frame number. And the second property sensor will check if the property is greater than your highest animation frame. If so, it should set the property to be your lowest frame number. And voila. Image of the logic setup:

This one only uses two frames (frame 1 and frame 2). In order to use more frames you would need to adjust the values on “greaterThan” and “Property1” in the image.

Put an integer property on your object called “PosNum” or whatever you want to call it. This will keep track of the object’s position (0-3).

from bge import logic, events

own = logic.getCurrentController().owner

[0,1,2], [10,4,2], [10,8,2] 

k = logic.keyboard


     own["PosNum"] += 1

    if own['"PosNum"] > len(positions) -1:
        own["PosNum"] = 0

elif C:
    own["PosNum"] -= 1
    if own["PosNum"] < 0:
        own["PosNum"] = len(positions) - 1

if own.worldPosition != positions[ own["PosNum"] ]:
    own.worldPosition = positions[ own["PosNum"] ]

Put this on a python controller, and connect it with an Always sensor set to true positive pulse.
Tapping spacebar will pop you to the next position on the list.
Tapping C will do the same in reverse order.
If you want to add/subtract/alter any of the positions on the list, just change the list. Much easier than setting up animation frames, placing empties, or any of that crud.

use nines script to move a objects steering target, use navmesh and steering actuator to follow path between points

You might want to have a look at

Thanks everybody. I set up the logic bricks as kendrick1397 described, and I get exactly the effect I was looking for. It’s easy to set the camera position with keyframes, just like one would do for an animation which makes it very easy. Then just make sure the last frame number is updated in the logic, and you’re good to go. I’ll probably put this logic on an empty and use it as a steering target to make things a little smoother.

I appreciate the other responses too. I started at the top of the list and was very happy to get what I needed on the first reply!