vector - positioning - python

Hi all

I am currently working on the tutorial part of my game. Here i also made it into a blendfile so you can take a look.

There is a target object , everytime when you click the keys (shown in the game), it should lead the other object to the position of the target. I dont know how to make it get snapped totally to the target object, and even its orientation.

Thank you in advance

Attachments

tutorial.blend (628 KB)

not sure if is this (not seem a good effect):


from bge import logic
from random import uniform
from mathutils import Vector


cont = logic.getCurrentController()
own = cont.owner
scene = logic.getCurrentScene()
obs = scene.objects


point = obs["tutopoint"]


u = cont.sensors["u"]
i = cont.sensors["i"]
o = cont.sensors["o"]
j = cont.sensors["j"]
k = cont.sensors["k"]
l = cont.sensors["l"]

loc = None


if u.positive:
    loc = [-1.9, 1.0, 1]
if i.positive:
    loc = [0, 1.0 , 1]
if o.positive:
    loc = [1.9, 1.0, 1]    
if j.positive:
    loc = [-1.9,-1.0, 1]
if k.positive:
    loc = [0, -1.0, 1]
if l.positive:
    loc = [1.9,-1.0, 1]
                
#if own.getDistanceTo(point) < 0.5:
    #own.worldPosition = loc
    #own.worldPosition = randPos()
    
#vec = point.getVectTo(own)[1]


#point.applyMovement(vec/5, False) #10
#point.alignAxisToVect(vec, 1, 0.05)
#point.alignAxisToVect(Vector((0, 0, 1)), 2, 0.05)
if loc:
    point.worldPosition = Vector(loc)







thanks Marco,

but it should have a transition movement between each positions…thats why i appied the vector parts

hum… this keep the transition



from bge import logic
from random import uniform
from mathutils import Vector


cont = logic.getCurrentController()
own = cont.owner
scene = logic.getCurrentScene()
obs = scene.objects


point = obs["tutopoint"]


u = cont.sensors["u"]
i = cont.sensors["i"]
o = cont.sensors["o"]
j = cont.sensors["j"]
k = cont.sensors["k"]
l = cont.sensors["l"]




loc = None 


if u.positive:
    loc = [-1.9, 1.0, 1]
if i.positive:
    loc = [0, 1.0 , 1]
if o.positive:
    loc = [1.9, 1.0, 1]    
if j.positive:
    loc = [-1.9,-1.0, 1]
if k.positive:
    loc = [0, -1.0, 1]
if l.positive:
    loc = [1.9,-1.0, 1]


if loc:
    own.worldPosition = loc
    
    
point.worldPosition = point.worldPosition.lerp(own.worldPosition, 0.05) 



thanks marco it looks better now

I usually use a simple vector to simulate slow parenting:

(This is just part of the script…)


target_vector = end-start

if target_vector.length >= 0.032:

    target_vector.length *= 0.032
    
    new_position = end - target_vector
    
    own.worldPosition = new_position

This makes the movement proportional to the distance to be moved. It’ll move quickly if the distance is large but more slowly as it gets closer.

MarcoIT’s lerp script probably does almost the same thing…

thanks smoking mirror