Lock Step (python orientation and position control) physical, and non physical

For in game alignment of objects, files at bottom of page

Using force and torque -> LockStepPhysics


import bge
from mathutils import Vector
cont = bge.logic.getCurrentController()
own = cont.owner
scene = bge.logic.getCurrentScene()




target= scene.objects['target']
Pos=own.worldPosition.copy()
distance = own.getDistanceTo(target)
vec = own.getVectTo(target)[1]
X1=own['X1']
force = vec * X1*distance
m1  = own.worldOrientation.copy()
m2  = target.worldOrientation
dif = Vector((m2 * m1.inverted()).to_euler())
x = dif.magnitude
if x > 1:
    x=1
force1 = own['Force']*own.mass


own.applyTorque(dif * force1*x, 0)


own.setLinearVelocity((0,0,0),0)
own.applyForce(force/distance, 0)
own.setAngularVelocity((0,0,0),0)



Using worldPosition+ alignAxistoVect() -> LockStep



``` import bge

def main():

cont = bge.logic.getCurrentController()
own = cont.owner


sens = cont.sensors['Named']
scene=bge.logic.getCurrentScene()
target=scene.objects['target']
TargetRot=scene.objects['Empty']
if sens.positive:
    Pos=own.worldPosition
    TPos=target.worldPosition
    if Pos.x<TPos.x:    Pos.x=Pos.x+.05
    if Pos.x>TPos.x:    Pos.x=Pos.x-.05
    if Pos.y<TPos.y:    Pos.y=Pos.y+.05
    if Pos.y>TPos.y:    Pos.y=Pos.y-.05
X =own.getVectTo(TargetRot.worldPosition)    
own.alignAxisToVect(X[1],1,.5)    

main()


### Attachments
<a class='attachment' href='/uploads/default/original/4X/8/a/b/8ab3f2335127eca0eb2a741551084f497eb4b63c.blend'>LockStepPhysics.blend</a> (462 KB)<a class='attachment' href='/uploads/default/original/4X/6/2/f/62f19df37cc858797e1a1d8600c64620db0a7e5f.blend'>LockStep.blend</a> (458 KB)

very useful! way smoother than just setting the position

I’m not sure what this is supposed to do - is it attempting to smoothly copy the rotation and position information from one object to another? If so, use lerping and slerping (for quaternion rotations) with a smooth factor ~ .2

Lockstep is a term used to describe game simulation where events happen in sequence. Typically belonging to multiplayer games where all other clients freeze their gamestate until one client has finished its move.

You don’t need to name every resource with a catchy title. If is is just a RayCast visualiser, then call it “Ray cast visualisation tool” rather than RayDraw or RayReCast etc. It makes it easier to search for too! :wink:

Otherwise, thanks for putting a video. I’ve not had time to watch it yet, (it’s late here) but it helps people understand what’s going on without downloading a source file.

It is a tool for cut-scenes, or for in game effects, missiles ?

it can do a lot,

good for physical systems as well as Ik targets,
statics etc.

I use LockStep - to switch from one set of animation handles to another :smiley: smoothly in game with a physical actor :smiley: