Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
2
Question by Jordan Miller 2 · Apr 30, 2010 at 12:38 AM · updaterespawn

respawn not working, transform.position

I have no idea why this code isn't working! it should. I have a character and a on that character I have a respawn.js. below is the code for it. now, it was originally working when I was using the update function as posted below, but when I take that out and put in the OnControllerColliderHit function (also listed below) it doesn't work anymore. you'll see 2 debug.logs in the forceRespawn function. the first debug gives me this:-362.9575 (transform.position.y) the second gives me this: 579.3809 (transform.position.y after the respawn but, my character doesn't actually move at all!). is there something about needing to move the transform in the Update function or what??

static var startingspawnpointx; static var startingspawnpointy; static var startingspawnpointz;

function Awake() { startingspawnpointx = transform.position.x; startingspawnpointy = transform.position.y; startingspawnpointz = transform.position.z; }

function Update() { //check if transform (what this script is connected to) fell off platform and respawn it. if(transform.position.y < -2000) { forceRespawn(); } }

function forceRespawn() { Debug.Log(transform.position.y); transform.position.x = startingspawnpointx; transform.position.y = startingspawnpointy; transform.position.z = startingspawnpointz; Debug.Log(transform.position.y); } function OnControllerColliderHit(hit: ControllerColliderHit) { if (hit.gameObject.name == "Respawn") { Debug.Log("about to"); forceRespawn(); Debug.Log("respawn"); } }

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 Chris 4 · Jul 17, 2010 at 05:15 PM 0
Share

$$anonymous$$y character does the same thing too except even thought I put him 9 meters above the terrain he goes through ONLY AFTER RESPAWN

avatar image skovacs1 · Aug 27, 2010 at 04:55 PM 0
Share

With Update as posted, it worked, but with the OnControllerColliderHit as posted in s$$anonymous$$d, it did not? You must have confirmed that your forceRespawn is firing and the positions you list are what you expect, but when running, it "doesn't work", right? Since the posted code seems fine, I can only think that it may be something else interfering - Are any other scripts moving the GameObject in question? (in theory it may have worked before because this script's update fired later than the other) Also, have you tried a Debug of the position in the update to confirm the respawn change is staying?

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by e-bonneville · Apr 30, 2010 at 01:01 AM

Wow, that's crazy. You're working way too hard. Try this simple code instead:

var SpawnPoint : GameObject;

function Awake() { SpawnPoint.transform.position = transform.position; }

function Update() { if(transform.position.y < -2000) { forceRespawn(); } }

function forceRespawn() { transform.position = SpawnPoint.transform.position; }

function OnControllerColliderHit(hit: ControllerColliderHit) { if (hit.gameObject.name == "Respawn") { forceRespawn(); } }

Just create an empty GameObject for your spawnpoint and drag it onto the open slot in the inspector when you put this script on your character.

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 Jordan Miller 2 · Apr 30, 2010 at 01:28 AM 1
Share

awesome idea man but it didn't work either. I land on the "Respawn" platform below my terrain and i just sit there. it doesn't move my "First Person Controller" transform to the "SpawnPoint" I did some trouble shooting and it does indeed go into the if statement and yet I don't move.

avatar image Eric5h5 · Apr 30, 2010 at 01:37 AM 1
Share

There's no need for empty game objects...change "`var SpawnPoint : GameObject`" to "`private var spawnPoint : Vector3`", change "`SpawnPoint.transform.position = transform.position`" to "`spawnPoint = transform.position`", and "`change transform.position = SpawnPoint.transform.position`" to "`transform.position = spawnPoint`". Also it's a good idea to use lowercase for variable names and uppercase for function names.

avatar image Jordan Miller 2 · Apr 30, 2010 at 01:47 AM 1
Share

ok, I did that Eric, good advice to tidy up the code, but the problem still remains. do I have to put it in like the update function? because that one works, but the Respawn platform doesn't work. (the OnControllerColliderHit function doesn't work)

avatar image e-bonneville · Apr 30, 2010 at 02:02 AM 1
Share

Well, the OnControllerColliderHit won't work unless your collider is not set to be a trigger... is that how you have it? And, @Eric, thanks for the suggestions. I can't fix the code right now, because I'm working, but I'll be sure to do that. I usually do name my variables in camelBack, but I just copied and modified his code.

avatar image xeophin · Jun 24, 2010 at 01:49 PM 1
Share

Are you using a rigidbody for your character? If I remember correctly, you can't use transform to move your character in this case, and have to use rigidbody.positionin this case.

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

No one has followed this question yet.

Related Questions

how do i make this to a negative (ShopRespawn < 180)? 1 Answer

boolean var generated in update not accessible 1 Answer

Stop Object from deleting HELP ME!!!!!!!!!!!! 1 Answer

How to Count an Input, key press on keyboard 1 Answer

Is Update() NOT linked with graphics refresh rate? 3 Answers


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