a few questions for all of the python gurus

hi,
I’ve currently started a new project about portals, so I asked Mr. Goran on his website and luckily I got the highest votes so he answered me (yes, I am EMC), so I used the portal script with his ray sensor tutorial to make the portal gun, but now I’m having a few problems; when the player gets in one of the portals while it is oriented in a weird way (for example on the graound), the player gets out of the other portal upside down so my question is : is there a way to make the player always fall on it’s “feet”?
and another problem that I had was that when I add a portal near the edge of a wall it generates most of the portal outside the wall (http://dl.dropbox.com/u/32414374/portal%20problem.PNG) (there is a ground where that wall ends, it’s just that I took a snapshot while I was falling :P) and that is a problem because when I enter the other portal (the orange one in this case) I come out falling because that part of the portal is outside, so is there a way to fix it?
Oh! and the portals have to be a specific distance from the wall for them to work, it’s not really a big problem but if there is a fix for it then that would be appreciated too :smiley:

I will add the name of the person who answers any of these questions in the credits so I think it would be cool, don’t u ;D

NOTE: I’m not very good at python stuff XD

oh c’m on guys, nothing!!?? :c

Physics? …of collision mesh, armature, model mesh and floor?, have you tried making it fall into the ground a little?, i dunno that script.

I can upload what I have right now if you want to see

ok, so I found a way to make the portals teleport almost like the actual game but it will take some time to make the actual level since I’m going to be making it out of non-scaled planes (2 layers), because I don’ know how to use python obviously XD, so it will require a fairly good computer to run the game, but I still have the player problem, which is to point it’s “feet” always to the bottom (-Z Axis)
so can any1 help me with that?

you may be able to solve this by using a constraint actuator. select “orientation constraint”, set “direction” to be “z-axis”, and for “Reference” set the zaxis to the maximum number, and this should work.

Easy enough would be this, add it after the movement part of the teleport script.
remember to import mathutils


# Assuming the player object is set
world_z = mathutils.Vector((0, 0, 1))
empty_vector = mathutils.Vector.Fill(3)
    
player.localAngularVelocity = empty_vector
player.alignAxisToVect(world_z, 2)

thanks guys! that really was kind of you :D, unfortunately I tried agoose77’s technique but I couldn’t get it to work, probably because I suck at python XD (I’m very new to python, in fact it is the first programming language that I’m learning) so I tried kendrick1397’s technique and it worked but I couldn’t move the player on the z-axis (for the mouselook script that I got from www.tutorialsforblender3d.com) so I tried to set a maximum point and it worked with 0.100. so now that this problem is over there is still the other one, which is the second one where the portal generates a little bit off the wall, so can any1 help me with that?

My method should work, just profide the player object, and import mathutils

I did import mathutils and I knew that the problem is from the player object (thank god for the console :P) but I didn’t know how to fix it, do you want to see the scrip?

Sure!
All you need to do is tell the script what the player object is. Post it up, i’ll take a look :slight_smile:

ok :smiley:
NOTE: this script doesn’t include your addition :stuck_out_tongue: so you can editit it however you want :smiley:
Script:

from bge import types, logic
from mathutils import Matrix
import math

class Portal(types.KX_GameObject):

def __init__(self, own):
    
    self.cont = self.controllers[0]
    
    self.sen_col = self.cont.sensors["Collision"]
    
def getTerminus(self):
    
    scene = logic.getCurrentScene()
    
    return scene.objects[self["Terminus"]]


def getTransMtx(self):
    
    mtx_to_ident = self.worldOrientation.transposed()
    mtx_flip_pi = Matrix.Rotation(math.pi, 3, "Y")
    mtx_to_terminus = self.getTerminus().worldOrientation
    
    return mtx_to_terminus * mtx_flip_pi * mtx_to_ident

def transport(self, gobj):
    
    mtx_trans = self.getTransMtx()
    
    gobj.worldOrientation = mtx_trans * gobj.worldOrientation
    gobj.setAngularVelocity(mtx_trans * gobj.getAngularVelocity())
    
    delta = gobj.worldPosition - self.worldPosition
    delta = mtx_trans * delta
    gobj.worldPosition = self.getTerminus().worldPosition + delta
    
    gobj.setLinearVelocity(mtx_trans * gobj.getLinearVelocity())

def thruHorizon(self, gobj):
    
    delta = gobj.worldPosition - self.worldPosition
    
    if delta * self.worldOrientation.col[2] < 0:
        return True
    return False

def main(self):
    
    if self.sen_col.positive:
        hit_obj = self.sen_col.hitObject
        if self.thruHorizon(hit_obj):
            self.transport(hit_obj)

def main(cont):

own = cont.owner

if not "init" in own:
    own["init"] = True
    Portal(own)
else:
    own.main()

import bge
import mathutils

class Portal(types.KX_GameObject):

    def __init__(self, own):
        
        self.cont = self.controllers[0]
        
        self.sen_col = self.cont.sensors["Collision"]
        
    def getTerminus(self):
    
        scene = logic.getCurrentScene()
        
        return scene.objects[self["Terminus"]]
        
        
    def getTransMtx(self):
        
        mtx_to_ident = self.worldOrientation.transposed()
        mtx_flip_pi = Matrix.Rotation(math.pi, 3, "Y")
        mtx_to_terminus = self.getTerminus().worldOrientation
        
        return mtx_to_terminus * mtx_flip_pi * mtx_to_ident
    
    def transport(self, gobj):
    
        mtx_trans = self.getTransMtx()
        
        gobj.worldOrientation = mtx_trans * gobj.worldOrientation
        gobj.setAngularVelocity(mtx_trans * gobj.getAngularVelocity())
        
        delta = gobj.worldPosition - self.worldPosition
        delta = mtx_trans * delta
        gobj.worldPosition = self.getTerminus().worldPosition + delta
        
        world_z = mathutils.Vector((0, 0, 1))
        empty_vector = mathutils.Vector.Fill(3)
        
        gobj.setLinearVelocity(mtx_trans * gobj.getLinearVelocity())
        gobj.setAngularVelocity(empty_vector)
        
        gobj.alignAxisToVect(world_z, 2)
        
    def thruHorizon(self, gobj):
    
        delta = gobj.worldPosition - self.worldPosition
        return (delta * self.worldOrientation.col[2] < 0)
        
    def main(self):
    
        if self.sen_col.positive:
            hit_obj = self.sen_col.hitObject
            
        if self.thruHorizon(hit_obj):
            self.transport(hit_obj)
        
    

def main(cont):

    own = cont.owner
    
    if hasattr(own, 'main'):
        Portal(own)
    else:
        own.main()

Next time use the code tags if possible (go into advanced mode and click the # symbol)

thanks, I didn’t know how to do the code tags :stuck_out_tongue:
awwwww maan! now I have another problem :’(
http://dl.dropbox.com/u/32414374/problem%20XC.bmp

thanks, I didn’t know how to do the code tags :stuck_out_tongue:
awwwww maan! now I have another problem :’(
http://dl.dropbox.com/u/32414374/problem%20XC.bmp

-_- I didn’t mean to post it twice :c



class Portal(bge.types.KX_GameObject):

    def __init__(self, own):
        
        self.cont = self.controllers[0]
        
        self.sen_col = self.cont.sensors["Collision"]
        
    def getTerminus(self):
    
        scene = bge.logic.getCurrentScene()
        
        return scene.objects[self["Terminus"]]
        
        
    def getTransMtx(self):
        
        mtx_to_ident = self.worldOrientation.transposed()
        mtx_flip_pi = Matrix.Rotation(math.pi, 3, "Y")
        mtx_to_terminus = self.getTerminus().worldOrientation
        
        return mtx_to_terminus * mtx_flip_pi * mtx_to_ident
    
    def transport(self, gobj):
    
        mtx_trans = self.getTransMtx()
        
        gobj.worldOrientation = mtx_trans * gobj.worldOrientation
        gobj.setAngularVelocity(mtx_trans * gobj.getAngularVelocity())
        
        delta = gobj.worldPosition - self.worldPosition
        delta = mtx_trans * delta
        gobj.worldPosition = self.getTerminus().worldPosition + delta
        
        world_z = mathutils.Vector((0, 0, 1))
        empty_vector = mathutils.Vector.Fill(3)
        
        gobj.setLinearVelocity(mtx_trans * gobj.getLinearVelocity())
        gobj.setAngularVelocity(empty_vector)
        
        gobj.alignAxisToVect(world_z, 2)
        
    def thruHorizon(self, gobj):
    
        delta = gobj.worldPosition - self.worldPosition
        return (delta * self.worldOrientation.col[2] < 0)
        
    def main(self):
    
        if self.sen_col.positive:
            hit_obj = self.sen_col.hitObject
            
        if self.thruHorizon(hit_obj):
            self.transport(hit_obj)
        
    

def main(cont):

    own = cont.owner
    
    if not hasattr(own, 'main'):
        Portal(own)
    else:
        own.main()

It’s alright, i made a mistake anyway.