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 iRaMb0 · Jun 28, 2013 at 11:18 AM · gameobjecttransformposition

Force object position

I want to make a script so when the player falls off the map the scene gets reseted...For some reason Application.loadLevel doesn't work so i wanted to just change the player's position so he is on the map again.I tried using this :

 #pragma strict
 
 var X : float;
 var Y : float;
 var Z : float;
 
 
 
 function Start () {
 
 X = transform.position.x;
 Y = transform.position.y;
 Z = transform.position.z;
 
 
 }
 
 function Update () {
 
 }
 
 function OnTriggerEnter(other : Collider){
 
 transform.position.x = X;
 transform.position.y = Y;
 transform.position.z = Z;
 
 }



but it doesn't work?! Any help would be nice

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

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by amphoterik · Jun 28, 2013 at 11:41 AM

I am assuming that the player is not the trigger. I assume the player falls into the trigger. Therefore, your solution would not work. The OnTriggerEnter would need to be on the trigger object. What I usually do for this sort of thing is create an empty game object where I want the character to spawn. I then create a script similar to this (note that I am not good with JS, please understand the intention and not the strict syntax):

 var spawnPoint: GameObject;
 
 function OnTriggerEnter(other : Collider)
 {
     if(other.tag == "Player")
         other.gameObject.transform.position = spawnPoint.transform.position;
 
 }

The spawn point will need to be dragged over to the script component in the editor. The player will need to be given the tag "Player". Then, whenever the player falls in, they get moved to the spawn point.

Comment
Add comment · Show 9 · 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 iRaMb0 · Jun 29, 2013 at 05:56 AM 0
Share

I tried it and it doesn't work :/ Also ,just to clear things out,I'm using a collider at the bottom of the map so when the player falls he goes back to the start...I tried using Application.LoadLevel with your "tactic" and it still didn't work...Also the "public var" should be just "var" :D

avatar image robertbu · Jun 29, 2013 at 06:03 AM 0
Share

The code should work if the trigger fires. What do you mean 'it doesn't work.' Does the trigger get hit? Is the spawnpoint correctly initialized? Put a Debug.Log() statement inside the OnTriggerEnter() to see if it is getting executed.

avatar image iRaMb0 · Jun 29, 2013 at 06:08 AM 0
Share

When i'm saying it doesn't work i mean that nothing is happening(?!)No Debug no nothing!!!

avatar image iRaMb0 · Jun 29, 2013 at 06:25 AM 0
Share

I tried it with an old Player i have and it worked so it must be something from the new one...Would "DontDestroyOnLoad()" prevent the player from changing position?

avatar image robertbu · Jun 29, 2013 at 06:27 AM 1
Share

No Debug.Log() output means your trigger is not going off? Verify that your collider has ISTrigger set. Verify that your player is intersecting the collider that has the trigger script. Verify that your player has a collider. Verify that either the trigger or the player has a Rigidbody.

Show more comments

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

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Best way to detect if an object is near? 1 Answer

[CODE]Keep Gameobject position exactly at mouse cursor when cast float position to int 1 Answer

postion scale and rotation greyed out and not working 1 Answer

Simultaneously moving GameObjects using C# script. 3 Answers

Slide GUITexture/GameObject into view? 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