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 charblaze · Jul 01, 2015 at 09:53 AM · transformplayerrandomtransform.position

Why does my player go to a random position after setting its position to a specific Vector3 and loading a level?

Hi, so in my game I have one doorscript which I put on all door objects so when they are activated they should send the character to a certain position (which i manually input as a public Vector3) and a certain level (which I also manually input as a string) all through the inspector

heres the gist of the script:

 using UnityEngine;
 using System.Collections;
 
 public class DoorScript : MonoBehaviour
 {
     GameObject player;
     public bool unlocked;
     public int Key;
     Spells spells;
     public bool LeadsToDifferentScene = false;
     public string LevelItLeadsTo;
     public Vector3 LocationItLeadsToInThatLevel;
     public bool quantumLeap = false;
     // Use this for initialization
     void Start()
     {
         player = GameObject.FindGameObjectWithTag("Player");
         spells = player.GetComponent(typeof(Spells)) as Spells;
     }
     public AudioClip lockedsound;
     public AudioClip opensound;
     // Update is called once per frame
     void Update()
     {
         if (tag == "Active" && unlocked)
         {
             AudioSource.PlayClipAtPoint(opensound, transform.position);
             if (!LeadsToDifferentScene && !quantumLeap)
             {
                 player.transform.position += player.transform.up * 1f;
             }
             else if (LeadsToDifferentScene && !quantumLeap)
             {
                 player.transform.localPosition = LocationItLeadsToInThatLevel;
                 Application.LoadLevel(LevelItLeadsTo);
                 
             } else{
                 player.transform.position = LocationItLeadsToInThatLevel;
             }
             tag = "Inactive";
         }
         else if (tag == "Active" && !unlocked)
         {
             if (spells.LookForKey(Key))
             {
                 unlocked = true;
                 // play unlocke sound?
                 AudioSource.PlayClipAtPoint(opensound, transform.position);
                 if (!LeadsToDifferentScene)
                 {
                     player.transform.position += player.transform.up * 1f;
                 }
                 else if (LeadsToDifferentScene && !quantumLeap)
                 {
                     player.transform.localPosition = LocationItLeadsToInThatLevel;
                     Application.LoadLevel(LevelItLeadsTo);
 
                 } else{
                     player.transform.position = LocationItLeadsToInThatLevel;
                 }
                 tag = "Inactive";
             }
             else
             {
                 AudioSource.PlayClipAtPoint(lockedsound, transform.position);
                 GameObject ohno = Instantiate(Resources.Load("Messages/OkMessage")) as GameObject;
                 OkMessage ohyes = ohno.GetComponent(typeof(OkMessage)) as OkMessage;
                 ohyes.message = "Locked";
                 tag = "Inactive";
             }
         }
     }
 }


On this particular door I have unlocked = true, leadstodifferentscene = true, levelitleadsto = MyLevelName, locationitleadstointhatlevel = the vector <17, 35, 0>, quantumleap = false.

It literally works for all of my ~20 doors that are in the game so far! For some reason this door isn't working and it is sending the player to the position <4.92, 19.2, 7.14> a seemingly completely RANDOM position!!?

Is it because the level isn't loading properly.. or what? This door is exactly the same as this other door that leads to <6, 36, 0> in the SAME EXACT SCENE and it works perfectly.

ALSO I used player.transform.localPosition because I tried it with player.transform.position thinking it would fix it, but it doesn't, it's the exact same result. The player object is not a child to anything so it shouldn't.

any ideas would be nice! thanks

Comment
Add comment · Show 2
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 charles1311 · Jul 03, 2015 at 06:31 AM 0
Share

Noob question. I am curious as to where the "Spells" constructor come from?

avatar image charblaze · Jul 09, 2015 at 09:49 PM 0
Share

spells is just a script / class I wrote and put on the player and it contains all item and spell info. This script just gets that and uses its LookFor$$anonymous$$ey method to see if the player has the key for the door (spells for me contains items as well)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by charblaze · Jul 10, 2015 at 08:38 AM

Hi actually I just figured out what is causing this... I was using the "dontgothroughthings" script i found online and it turns out my door was transporting me such a large distance it was glitching me out because of thsi script. So i just disabled it and now it works perfectly!! Sometimes the answer to your problem is completely unrelated to what u think the problem is.

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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

My character's y position gets reset on play. 0 Answers

How do you make a player move on a remote items local axis? 0 Answers

How to spawn objects on a restricted sphere surface relative to camera? 1 Answer

Setting Player positioning on a different loaded scene with Dont Destroy On Load attached. 0 Answers

Getting and sending a gameobjects position to another gameobject. 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