Possible Bug?


this is a little in depth,

To reproduce my issue grab this file


press 1 to spawn a component
press space to parent it to the “host” object

press 1 again to spawn another component and space to
parent it to the first added component

press z to move the spawner and player back slightly,

press 1 again to spawn another component and space to parent the component to the second added component

The error / bug I see is that the third cube is parented and moved much further apart then it should.

Any help would be greatly appreciated,

The code that moves + parents the item is python called “DetectSocket”

import bgefrom bge import render
import mathutils

cont = bge.logic.getCurrentController()
own = cont.owner
sens = cont.sensors['mySensor']


End = own.localPosition.copy()
hitOb, hitPoint, hitNormal, hitPoly = own.rayCast(End, Start, 0, 'Component', 0, 0, 1)

if hitPoint:
poly = hitPoly
## now how do I use polyproxy to get the material?
if hitPoly:
    hitMat = hitPoly.material_name
    if 'Link_' in hitMat:
        if hitOb[hitMat]==False:
            if own['Linked']==0:
                hitObPos=hitObPos+hitNormal ## Code that places item
                Diff = own.worldOrientation+hitOb.worldOrientation
                own.alignAxisToVect(-hitNormal, 1, 1)
                own.applyMovement((0,-2,0),1) ## item offsets self


ParentAndUnparentWithPropertyStoredAsMaterial.blend (1.4 MB)


and a fun little video

I’m not sure if this will cause problems with your game or not, but maybe in line 30 of your script you can change
hitObPos=hitOb.localPosition.copy() to hitObPos=hitOb.worldPosition.copy()

It looks like that is it :smiley:

Hi BluePrintRandom,

I looked at your file. I think it is a bit hard to read as there are mostly generated names at the blocks.
I rebuild your file in a way that I think it is more understandable. But I do not know the purpose of all the little details you added. So I was not able to care all of them. Good news is I think I found your problem (see below).

I tried to give the logic bricks names to describe what they should do (my guess). Be aware you hard coded these names in your code. This makes it very hard for you to change them as you need to change the code as well.

I notified you use True Pulse really a lot. I suggest you be a bit more careful with that as this increases workload. In most of the cases it is not necessary. (Interestingly I think I found a bug in BGE 2.69’s keyboard sensor. But I will care of it separately.)

I hope you know a difference is when you perform a substraction of one term from another:

Diff = own.worldOrientation+hitOb.worldOrientation

An addition might work (if one term is negative) but it is not the difference of the terms. It means the terms are incorrect.

You better avoid to substract or add matrizes (orientation). It seems you do not need this information. Better skip it. At least I do not know why it is present.

I strongly recommend to use some complete and descriptive names. All this “sens”, “Miss”, “hitObPos” do not let me guess any meaning, leaving me with a lot of question marks above my head.
As you have a computer there is no problem to type full names like: raySensor, hitObjectPosition
A “sens2” is a no-go. If you have multiple objects of the same purpose … use a list. Otherwise think about what is special on this particular instance.
Believe me your code will be much easier - not just for me :wink: .

Your problem


You copy the local position, which describes the position relative to the parent.
You need the world position, which describes the position relative to the scene.


This should solve your problem.

Edit: seems I’m a bit late now ;).


ParentAndUnparentWithPropertyStoredAsMaterial_revised.blend (1.35 MB)

Thanks Monster,
Thank you scuba,

It’s always nice to see people able dig through my obfuscated code and find the “needle” in the python stack. :smiley:

It was late on my end when I posted :smiley:

I have been nursing a sick little girly back to health, and she was up most of the night. :no:

Here is the file with that changed, and a few other minor changes.


WrectifiedGrabdParentAndUnparent.blend (1.51 MB)