- Home /
How to send a gameobject to a sepcific position in the 3d environment?
I do have a fps character and if this character touches the cube!! it should spawn in a secific point in the 3d environment!
How to code that? How to get to know a specifiv point in my world?
function OnTriggerEnter (myTrigger : Collider) {
if(myTrigger.gameObject.name == "First Person Controller"){
//here should be the script to spawn the fps controller at a specific point!
}
}
Celofa
Do you simply want to move the object to a new location? (I.e. 'teleport' it?) Or do you actually want to spawn (instantiate) a new game object?
Be sure to check one of the answers as 'accepted' so that the question doesn't continue to show up in the 'unanswered' category.
Answer by Jesse Anders · Jan 07, 2011 at 03:06 PM
If you simply want to 'teleport' the other object to a new location, try (untested):
function OnTriggerEnter(other : Collider)
{
if (other.gameObject.name == "First Person Controller") {
other.transform.position = ...position you want to teleport to goes here...;
}
}
Where the target position comes from is up to you.
yeahh sry for the answer(and not commenting thing)! that works thx!
Answer by Justin Warner · Jan 07, 2011 at 02:40 PM
var prefab : Transform; var spawn;
function OnTriggerEnter (myTrigger : Collider) { if(myTrigger.gameObject.name == "First Person Controller") { Instantiate (prefab, spawn.transform.position, Quaternion.identity); } }
Drag and drop an empty game object where you want the object to spawn in to the var spawn. And the prefab you want spawned in to the prefab section.
THis is a very common question, search before asking, =).
Hope this helps though, and I did it here, didn't test, so it might need tweaked lol.
Oh, if you want to move it to a location, than I'd suggest using: http://itween.pixelplacement.com/ and http://dkoontz.wordpress.com/2010/10/27/itween-visual-editor/ as you're new.
I've tried this code but it says that 'transform' is not a member of 'Object'. What will I do?
Answer by Celofa · Jan 07, 2011 at 03:05 PM
Itween seems to be a cool library, but i dont need to have the moving process!! I just want the gameobject to be at a other position without any movement animation!!
how to do that?? i hope u understand me!
Celofa
Be sure to post follow-up questions either as comments or edits to your original post, and not as answers.