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 zmar0519 · Jan 28, 2011 at 06:04 PM · instantiaterespawn

Respawn Point respawning far away

I am working on a marble raceway game where the player can roll around and if his life gets to zero, he respawns. the respawn script basicly sends the spawner gameobject to the latest collision between the player and a respawn point, so when the player dies, the last respawn point that he hit is the one that he starts at. but when I test it, the player respaws roughly 90 units away from the spawn point. My respawn Manager code looks like this :

var marbleLocomosion : Transform;

var marbleHealth : MarbleScript; var marbleCameraTransform : SmoothFollow;

function Awake() {

} function Respawn() { var clone : Transform; Destroy(marbleLocomosion); clone = Instantiate(marbleLocomosion, transform.position, transform.rotation); marbleLocomosion.position = transform.position; marbleHealth.health = 100; marbleCameraTransform.target = marbleLocomosion; }

and my respawn point script looks like this:

var CurrentPosition : Vector3;

var Manager : Transform;

var particleAnimator : ParticleAnimator;

private var manager : RespawnManager;

var isActive : boolean = false;

function Awake() { manager = FindObjectOfType(RespawnManager); } function Update () { CurrentPosition.x = transform.position.x; CurrentPosition.y = transform.position.y; CurrentPosition.z = transform.position.z; if(Manager.transform.position == CurrentPosition) { isActive = true; } else { isActive = false; } if(isActive == true) { particleAnimator.doesAnimateColor = true; } if(isActive == false) { particleAnimator.doesAnimateColor = false; } } function OnTriggerEnter() { Manager.transform.position.x = CurrentPosition.x; Manager.transform.position.y = CurrentPosition.y; Manager.transform.position.z = CurrentPosition.z; }

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

2 Replies

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

Answer by Jessy · Jan 28, 2011 at 07:20 PM

Like Jason B, I see nothing wrong with your code, other than the fact that it is really verbose! Here's the exact same thing without a bazillion lines!!! :-O

var marbleLocomosion : Transform; var marbleHealth : MarbleScript; var marbleCameraTransform : SmoothFollow;

function Respawn() { Destroy(marbleLocomosion); marbleLocomosion = Instantiate(marbleLocomosion, transform.position, transform.rotation) as Transform; marbleHealth.health = 100; marbleCameraTransform.target = marbleLocomosion; }

.

var particleAnimator : ParticleAnimator;

private var managerTransform : Transform;

function Awake() { managerTransform = (FindObjectOfType(RespawnManager) as Component).transform; }

function Update () { particleAnimator.doesAnimateColor = managerTransform.position == transform.position; }

function OnTriggerEnter () { managerTransform.position = transform.position; }

Don't name something ...Script, though. It's a script, we know that. Marble, not MarbleScript. That whole variable is bad practice. This is better:

var marble : Marble;
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
1

Answer by Jason B · Jan 28, 2011 at 06:53 PM

Have you tried testing multiple respawn points? Do you always respawn at the same relative offset?

I don't see anything in your code that's telling your spawn points to have any sort of offset. So that leads me to believe your spawn points may be parented to something. Are they?

If so, your spawn points are using their own local coordinates and not world coordinates to display their location. For instance, for a child object, 0, 0, 0 isn't the center of the world, it's the center of whatever it's parented to. So getting its position will return 0, 0, 0, and then sending you there will instead be like sending you back to the center of the scene rather than to the spawn point since your character is (assuming) not parented to anything so moving its position will move it in world coordinates.

Anyways, I'll try not to blather too much on this point if this isn't even what the issue is. :)

But if your respawn points are parented to anything, one (of a few) solutions could be to child your character to the respawn point parent, then set its position, then unparent it (a quick and dirty fix, but a fix nonetheless!).

Comment
Add comment · Show 4 · 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 zmar0519 · Jan 28, 2011 at 08:55 PM 0
Share

Thanks, but it didn't work. I am still respawning far a away and none of the respawn points are parented or parents to anything. I also put a box under the respawned marble, and I found that none of the components have been added except for those refrenced(the marble script and the smooth follow). I think that it is continuously instantiating and destroying at the position of the marble, not the respawn points. I go to the far away place ( about -86 from the respawn point) and respawn and destroy forever. HELP!! I need to finish this game very soon!!

avatar image zmar0519 · Jan 28, 2011 at 09:47 PM 0
Share

I just figured out the multple respawn problem, so when I continuously went through the damage, I went to a far closer place on one of the respawn points(the one that sent me far away) and on the other one, slightly left. there seems to be some anonymous line of code that sets my position, but I can't seem to find it. if you need to see the marble script, please just ask and i will post it in an answer.

avatar image Jason B · Jan 28, 2011 at 09:49 PM 0
Share

Is it necessary to destroy the marble only to reinstantiate it? Have you tried just moving it and resetting its health? Anyways, the reason your marble is instantiated as a component-less object is because according to your script, marbleLocomosion is nothing but a transform. You'll need to rewrite that variable as a GameObject, and link it to a prefab from inside the inspector.

avatar image Jason B · Jan 28, 2011 at 10:02 PM 0
Share

Anyways, I don't know how you're handling respawn points, but how often you check health shouldn't cause any problems. All I would do is basically have the points be trigger boxes, and when you hit them, they set some sort of spawn position variable. And when you die, you move position to that variable (or instantiate to it). There shouldn't be any possible way for it to go wrong. I guess I'd have to see more code, because this should be fairly straightforward and I'm not sure why any problems even exist. :(

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

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Instantiate GUI text 1 Answer

Terrain with lots of objects 1 Answer

cannon script is not working, no errors. 1 Answer

object count cap? 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