ok im working on a scene / map in my game but im stuck at a part.
so the map has a floating city basicly a city in the sky now for one my characters fall right though the city to the terrain and second
im trying to add a teleport to go from the ground to the city the teleport model is set to istrigger but how do i get it to trigger then pop up a box giving a selection where to transport it to also how to transport to another scene to a location set forth?
also when setting a character controller does it need to be set to the camera or can u set it on a model? i have it set on a model and it isnt moving but when set to a camera it leaves the model behind so kinda confused on it
As for the actual teleportation. I would say you would store an array of the positions of the various teleportation point and just change the player’s position to the point you want to go based on the selection.
transform.position = teleportationPoint[0]; // Moves player to the first point in the array
I swap player with teleport point because it seemed like a better idea to check if it’s a teleportation point you entered rather than have the teleport point check if you have entered. It’s preference really, you can make it work by checking the player and assigning the script to the teleporter. Still, tweak it based on what you need.
var teleportationPoint[0] = (x, y, z); // array coords
just trying to learn the proper way of writing this
and ok if its possible to attach it to any objects why isnt my main model moving when attached? also do u by any chance have a proper 3rd person script made u can share with me?
The array is of type Transform. I was assuming you would be passing it in via the inspector…
If you’re doing a Vector3 array, it would be like this:
public Vector3[] teleportationPoint;
public float x;
public float y;
public float z;
void Start()
{
teleportationPoint = new Vector3[1]; // Array size of 1
teleportationPoint[0] = new Vector3(x, y, z); // Passing in the coords
}
If your model is not moving, have you tried changing the values of the character controller in the inspector? I don’t actually have a 3rd person character controller with me now at this current moment (since I’m not at home at all and the project is in my computer at home). I do believe that there is a 3rd person shooter game project demo on the Unity website (it’s not Bootcamp) which has a 3rd person character controller. I…just…don’t know where it is anymore… =(
i dont get how the file is suppost to start this is wat it currently looks like
// Moves player to the first point in the array
public Vector3[] teleportationPoint;
public float x;
public float y;
public float z;
void Start()
{
teleportationPoint = new Vector3[1]; // Array size of 1
teleportationPoint[0] = new Vector3(x, y, z); // Passing in the coords
public Transform[] teleportationPoint;
public bool canTeleport = false;
}
void OnTriggerEnter(Collider other)
{
if(other.tag == "TeleportPoint")
{
canTeleport = true;
}
}
void OnGUI()
{
if(canTeleport)
{
// Popup message here
if(Button(new Rect(0, 0, 100, 20), "Sky City"))
{
transform.position = teleportationPoint[0].position;
}
}
}
You weren’t suppose to outright copy…I suggest you take some lessons on scripting.
public Vector3[] teleportationPoint;
public float x;
public float y;
public float z;
public bool canTeleport = false;
void Start()
{
teleportationPoint = new Vector3[1]; // Array size of 1
teleportationPoint[0] = new Vector3(x, y, z); // Passing in the coords
}
void OnTriggerEnter(Collider other)
{
if(other.tag == "TeleportPoint")
{
canTeleport = true;
}
}
void OnGUI()
{
if(canTeleport)
{
// Popup message here
if(Button(new Rect(0, 0, 100, 20), "Sky City"))
{
transform.position = teleportationPoint[0].position;
}
}
}
Also, I only put in the x, y and z variables just so it won’t throw any error. I was expecting you to either hardcode the position by yourself or to fill it up in the inspector. Really, I suggest that you take up some tutorials on scripting.
i have the problem isnt the script im aware the spaces im suppost to fill in the problem is am i suppost to use function start () or update at the very top? where it says public Vector3[ ] teleportationPoint; or is that proper?
Those are variables that you are declaring to be used in classes (by my definition). If you declare them in functions, those variables are temporary and will be destroyed (I think it’s destroyed?) at the end of the function.
Seriously, go pick up a scripting tutorial, learn to code before you start coding, really, please, for the sake of all the programmers who will help you in the future.
ive already study’ed using the unity3d’s video tuts off TPB
i just got alil confused on those parts xD happens to the best of us ya know im actualy a c and c++ linux programmer so as far as JS goes im fairly new but i know my ways around but the way unity reads it is entirely new to me thats why im asking. also when attaching the script the teleport pad i get this in the console:
can u explain the problem here as i dont get it =\
also the error :
Assets/Scripts/teleport/teleport.js(2,8): BCE0043: Unexpected token: Vector3.
(Filename: Assets/Scripts/teleport/teleport.js Line: 2)
Assets/Scripts/teleport/teleport.js(3,8): BCE0043: Unexpected token: float.
(Filename: Assets/Scripts/teleport/teleport.js Line: 3)
Error: Analytics Event: 5(Compiler*BCE0043*Unexpected token: float.)(1): skipped because it was sent more than once in 0.10 seconds
Assets/Scripts/teleport/teleport.js(4,8): BCE0043: Unexpected token: float.
(Filename: Assets/Scripts/teleport/teleport.js Line: 4)
Error: Analytics Event: 5(Compiler*BCE0043*Unexpected token: float.)(1): skipped because it was sent more than once in 0.10 seconds
Assets/Scripts/teleport/teleport.js(5,8): BCE0043: Unexpected token: float.
(Filename: Assets/Scripts/teleport/teleport.js Line: 5)
Assets/Scripts/teleport/teleport.js(11,1): BCE0044: expecting }, found 'public'.
(Filename: Assets/Scripts/teleport/teleport.js Line: 11)
Assets/Scripts/teleport/teleport.js(11,17): UCE0001: ';' expected. Insert a semicolon at the end.
(Filename: Assets/Scripts/teleport/teleport.js Line: 11)
Error: Analytics Event: 5(Compiler*UCE0001*';' expected. Insert a semicolon at the end.)(1): skipped because it was sent more than once in 0.10 seconds
Assets/Scripts/teleport/teleport.js(11,19): UCE0001: ';' expected. Insert a semicolon at the end.
(Filename: Assets/Scripts/teleport/teleport.js Line: 11)
Assets/Scripts/teleport/teleport.js(12,8): BCE0043: Unexpected token: bool.
(Filename: Assets/Scripts/teleport/teleport.js Line: 12)
Assets/Scripts/teleport/teleport.js(13,1): BCE0044: expecting EOF, found '}'.
(Filename: Assets/Scripts/teleport/teleport.js Line: 13)
Refresh, detecting if any assets need to be imported or removed ... 0.085407 seconds (Nothing changed)
puzzles me
i also filled in the script with the new coords and attached it to the teleport model. what am i missing ive written every other script i have and this one is giving me so many problems
and that unexpected token is still trying to eat me what does it mean unexpected token vector3? these are things ive been asking and i get no answer to from the way i have it coded i shouldnt be getting that yet i am and i cant make heads or tails of why its giving me that
The path that you are trying to call from is invalid. Basically, Button can’t be called since the path is invalid so you need to tell it that you are calling it from the GUI class using GUI.Button.
ok u tell me that about the button and what do but u dont explain how to make it call that class? lol i know some javascripting but unity uses a diff framework and structure so some things im alil puzzled on. if that makes any sense at all
all ur doing is bloody confusing me -.- this is pointless u give me examples i attempt to use them within my own coding yet when i do use parts of it it will throw up errors at me and break my entire coding i cant even attempt to test the scripts till these are fixed now -.- and all ur doing is playing word games without examples i dont learn from words i learn from seeing how it works what is passed etc a basic stucture is all i need from start to finish so i can add my own coding within without breaking it the way ur showing me the code is just breaking everything can u help me with a basic stucture so i can make this work cleanly or are u just gonna keep making me guess everything and break it even more?
Hence my point about picking up some scripting tutorials. Well, okay, I accept that I forgot to add GUI. behind (I blame lack of sleep) but really, if you had tried out some simple tutorials on scripting for GUI, everything starts with GUI. I’m not blaming you for anything (if you assumed I did). Also, the Javascript in Unity is different from the web Javascript. I believe the Javascript (or Unityscript as I like to call it), follows closely with Actionscript (which is Flash language).
Can you show me your script again (so I can help you debug the unexpected token bug)? You are using C# for this right? I’ve been showing you codes for C#. If you need it as Javascript, I’ll need awhile to convert it. Although for arrays in JS, I don’t actually know how to write those.
i told u i already watched the bloody tuts on it ive been at this for alil over a month ive written a few scripts yet i lack the ability to complete the 3rd person controller and the teleport scripts with those the rest should be nearly complete and can fully continue on this and i know how that lack of sleep goes ive been up 3 days now working on this and i cant fall asleep till its done and its really pissing me off cause i cant see my errors everything looks correct to me and c# o.o well that explains alot lol im not fluent in c# im currently using JS for the time being? but question does c# give more functions?