how would you set a players location and orientation smoothly (with python)?

Lots of Games have the cut scene transition where you press a button, your character moves to a certain position and orientation (smoothly not instantly) and then it plays an animation, of them getting into a chair or picking something up etc.

How would you set this up with python?
I haven’t learnt much so a simple explanation/example would be greatly appreciated:D

i have this same question, it might be that other game engines have an option to turn slow parenting on and off in-game. I’ve seen it in god of war, when you press O you can (smoothly) move to the enemies position and rip its head off or something.

*** moderation
Action: Merged 4 posts
@BluePrintRandom: Use The Edit button. I’m sure you can see it in your browser and your mouse will not kill you when clicking on it.
end of moderation ***

I would use align axis to vect, and use a empty (target of position) with a empty parented to it (align axis to)

and you can either apply force, etc, or do

if own.x>target.x: own.x=own.x-.01
if own.x<target.x: own.x=own.x+.01

if own.y>target.y: own.x=own.y-.01
if own.y<target.y: own.x=own.y+.01

here ya go :smiley:

this handles X,y and rot

you can adjust values,

I can also use physics to move the player if need be

and physics version

Accidental overpost

Attachments

LockStep.blend (458 KB)LockStepPhysics.blend (462 KB)

This is really helpful thanks!

You can dynamically manipulate the offset of slow parent. But it makes no sense in this example, as I’m sure the character is not supposed to fly in a straight line towards the target pose.

blend = 15              #smoothness

obj1pos = yourObject.worldPosition
obj2pos = yourSecondObject.worldPosition         #you can use a vector instead

obj1rot = yourObject.worldOrientation
obj2rot = yourObject.worldOrientation

rotdif = Vector((obj2rot * obj1rot.inverted()).to_euler())
posdif = obj2pos.worldPosition - obj1pos.worldPosition

yourObject.applyMovement(posdif/blend, 0)
youObject.applyRotation(rotdif/blend, 0)

It can be simplified into like 4 lines but this will make it clearer. You can remove the rotation related lines if you want position only.

I might use this script if i can get it to work because this will probably be used on a dynamic character.

The Main problem at the moment is generating a true pulse one both loc and rot are met…
(if obj1rot == obj2rot:
own.activate [“true”]
??)

If you want a smooth and simple result you could simply parent the player to the target location object and use slow parenting value.
this would align and move child smoothly to the parent. After that just remove the parenting.

EDIT: Bleh my method is no use. timeOffset doesn’t work if you parent object via Python. It only works on already parented objects with “Slow Parent” option selected.

My concept would have been something like this:


    if k.positive:
       obj.setParent(target)
       obj.timeOffset = 200
       target.worldPosition = [random.uniform(-5,5), random.uniform(-5,5), 0]

    if sum(obj.linearVelocity) &lt;= 0.0:
       obj.removeParent()

Its an interesting concept however how would you activate a true pulse after the motion is finished?

I would have probably used states if it had worked.

EDIT: I used slow-parenting on making a simple elevator on my first-person project. I simply move the empty which is parent to the elevator object with enough slow-parenting on. works quite well if you don’t count the “nudge” at beginning and slow stopping at end :smiley:

EDIT 2.0: That was one weird edit…I was suppose to edit and not answer to myself.

I would have used the worldPosition.lerp function


speed = 0.5
playerPosition = player.worldPosition.lerp(otherObject, speed)
player.worldPosition = playerPosition

speed is the size of the steps the lerp function takes to get to the required positions.

same thing can be done for the worldOrientation of the player.

NICE!

I never knew about lerp!