Brafil
(Brafil)
May 10, 2008, 3:49am
1
Hi Im working on a Teleport script. If the Object touches a “Gate”, it should be transmitted to the empty. but what``s wrong here? It doesn`t teleport nor gives an Error.
import GameLogic as GL
cont=GL.getCurrentController()
Own=cont.getOwner()
Scene=GL.getCurrentScene()
getObj=Scene.getObjectList()
Phantomy=getObj["OBPhantomy"]
Place=Own.teleport
Empty=getObj[("OB"+Place)]
Phantomy.setLocation(Empty.getLocation())
Brafil
(Brafil)
May 10, 2008, 6:20am
2
Ok Sorry, After controlling the Properties, I found it.:o The script wasn’t used, so nothing can go wrong.
Hey Im wanting to make a game where you can push space in the game and you teleport to wherever a specific object is. I know that this script below makes my object snap to a certain position…
cont = GameLogic.getCurrentController()
obj = cont.getOwner()
obj.setPosition([4, 0, 0])
but whats a script that can set my object’s position based on where another object is?
cont = GameLogic.getCurrentController()
obj = cont.getOwner()
sce = GameLogic.getCurrentScene()
target = sce.objects[‘Target’]
obj.setPosition(target.getPosition())
Might work, but it’s untested.
Well, if this is the game engine then it should look like this:
cont = GameLogic.getCurrentController()
obj = cont.getOwner()
sce = GameLogic.getCurrentScene()
target = sce.objects[‘Target’]
obj.position = target.position
Is there something i did wrong on this script cuz nothings happening even after i set the Logic Bricks.
import GameLogic
cont = GameLogic.getCurrentController()
obj = cont.getOwner()
sce = GameLogic.getCurrentScene()
target = sce.objects[‘Target’]
obj.position = target.position
agoose77
(agoose77)
May 27, 2011, 11:20am
8
Have you tried looking at my teleport script for 2.5?
http://blenderarchive.hostilestudios.com/list.php
look at teleport!
SolarLune
(SolarLune)
May 27, 2011, 12:18pm
9
Yeah, I assumed that you’re working with 2.49 by how you’re using GameLogic, but if you’re in 2.5, the API is different. It should be:
from bge import logic
cont = logic.getCurrentController()
obj = cont.getOwner()
sce = logic.getCurrentScene()
target = sce.objects['Target']
obj.position = target.position
If a script doesn’t work, look at the console for an error. If the console isn’t visible, go to the Help menu and enable it.
ah… I meant to say 2.5 not game engine. And shouldn’t it be:
obj = cont.owner
instead of
obj = cont.getOwner()
This thread is a mess of do this…
Ex.
SolarLune
(SolarLune)
May 27, 2011, 12:38pm
11
Ah, Excaliburr’s right. I kept in the 2.49 method of referring to things - he’s right, it should be:
Yeah, I assumed that you’re working with 2.49 by how you’re using GameLogic, but if you’re in 2.5, the API is different. It should be:
from bge import logic
cont = logic.getCurrentController()
obj = cont.owner
sce = logic.getCurrentScene()
target = sce.objects['Target']
obj.position = target.worldPosition
I’m even getting confused with all these comments. Here are 2 examples one for 2.5 and one for 2.49. Tested and working.
2.5: http://www.pasteall.org/blend/6701
2.49: http://www.pasteall.org/blend/6702
Controls:
Press Spacebar to move the cube to the empty named “Target”
Hope this helps -
Ex.
Thanks alot guys! It works now. Im also trying to make a property that can randomly choose a certain value. I made an integer property and i want it to randomly change its value from 0 to any number no greater than 15. How can i do this? Do i use the Random Sensor or some script?
kurotatsu
(kurotatsu)
July 16, 2011, 11:47am
14
Check my random example in my sig.