Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by vertex · Oct 11, 2010 at 03:46 PM · playerspawnleveltransitionpoint

spawn points/ player transition from level to level with multiple exits and entrances

The following script is supposed to a) look at the last level loaded. b) spawn the player to a game object position in the new scene/level loaded.

I am failing to integrate it properly. I am new to scripting. I have tried to integrate the Awake() function but failed. I suspect this is the trouble? Code/syntax help appreciated.

I have set the var character1 and fromThisLevel on the game object/spawn point with script attached.

The new level is loading with a grey screen and no player instantiated.

var character1: GameObject; var fromThisLevel = 0;

function OnLevelWasLoaded (level : int) { if (level == fromThisLevel) { print ("Woohoo"); Instantiate(character1,transform.position,transform.rotation);}}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Feb 01, 2011 at 05:36 PM

If you want a continuous level like in Halflife where when you enter the end-of-level trigger it loads a new level around you. The two levels are overlapping a bit so that after the loading it looks like you're still in the same level at the same position. There are even levels that have multiple transition points like you mentioned. In Halflife they use "info_landmark" nodes inside the levels to match up the two levels.

The player object should not be deleted in this case and don't need to be instantiated again. Just be sure to mark the player object with DontDestroyOnLoad.

That's how a landmark node script could look like:

 public var name : string;
 private static var m_oldPosition : Vector3;
 private static var m_oldName : string;
 
 public static function GetOffset() : Vector3 {
     var landmarks : Landmark[] = FindObjectsOfType(Landmark);
     for (int i = 0; i < landmarks.Length; i++) {
         if (landmarks[i].name == m_oldName) {
             return (landmarks[i].transform.position - m_oldPosition);
         }
     }
     return Vector3.zero;
 }
 
 public function UseLandmark() {
     m_oldName = name;
     m_oldPosition = transform.position;
 }

On the end-of-level trigger:

 var levelname : string;
 var landmark : Landmark;
 
 function OnTriggerEnter() {
    landmark.UseLandmark();
    Application.LoadLevel(levelname);
 }

and inside your gamelogic :

 var playerObject : GameObject;
 
 function OnLevelWasLoaded (level : int) {
    Vector3 offset = Landmark.GetOffest();
    playerObject.transform.position += offset;
 }
          

    




Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by DannyJax.du · Oct 12, 2010 at 03:10 AM

look in the Lerpz tutorial, it has a script in it that if Lerpz falls off the platform and hits a collision detection, he disappears and re-spawns on a platform he previously stored his location to. That script can be converted to do what you want. There are as many spawn locations in the level as you place. I placed like 3, and they worked, I then placed about 10 more and they all worked.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image superventure · Feb 21, 2011 at 05:36 AM 0
Share

I think he meant between different levels, not in one scene.

avatar image
0

Answer by superventure · Feb 21, 2011 at 06:37 AM

I was grueling over the exact same problem, and JUST thought of this- It's working out for me, I hope it helps you too-

The problem is that we want to begin at one of any specific points. We were looking at it in a dead end way though. When you load a level, you usually have one spawn point with code to 'JUST START HERE'. We need be able to carry on info from the last level to tell the new level that you want to start at ANY specific point you specify.

I think Bunny83 just descirbed this but I don't understand all that :p...

I thought this could be done with a kind of scoring method that all spawn points could look at. This could done in a much simpler way, so fix it up how you want

Make 3 (or however many) spawn points you want in your levels and tag them startpoint1, startpoint2, etc, and add something like this to them ( I used empty game objects)

function Start() {

if(Player.teleporter == 1){

start1();

}if(Player.teleporter == 2){

start2();

}if(Player.teleporter == 3){

start3();

} }

function start1(){

var Player = GameObject.Find("Player"); var startpoint1 = GameObject.FindWithTag("startpoint1").transform;

Player.transform.position = startpoint1.position;

}

function start2(){

var Player = GameObject.Find("Player"); var startpoint2 = GameObject.FindWithTag("startpoint2").transform;

Player.transform.position = startpoint2.position;

}

function start3(){

var Player = GameObject.Find("Player"); var startpoint3 = GameObject.FindWithTag("startpoint3").transform;

Player.transform.position = startpoint3.position;

}

Have the actual 'teleporting game object' (a door, a floor pad, something) and add a collider set as a trigger and add this

function OnTriggerEnter(other : Collider) {
    Player.teleporter = 2; // whatever number to correspond to where you want to spawn
Application.LoadLevel("cave");
}

on the player's script add this in the update function

DontDestroyOnLoad (this);

and add at the top of the script

static var teleporter = 0;

Do you get the set up? When you hit the exit or 'teleporting game object', you set the players teleporter number to the specifically numbered spawn point you set in the new level.

You'll have to make multiple application.Loadlevel scripts to set the specific numbers, but it works in the long run.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Michael 12 · Apr 09, 2012 at 08:45 PM 0
Share

I must be missing something here I'm trying it out and I get a "$$anonymous$$ identifier: 'Player'." error message??

avatar image gv1351 · Aug 01, 2014 at 02:07 PM 0
Share

I got a error where the word teleport is. What must I do?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Score Question Java Script, problem 1 Answer

Player spawn after touching 0 Answers

Spawn Player when Room Starts - (Multiplayer) 1 Answer

Player spawns facing the wrong direction. 2 Answers

An easy way to add level transitions? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges