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 Spilker · Feb 05, 2012 at 12:27 AM · triggerrespawn

Trigger Respawn

I'm making car game, and you pull up to a intersection and you have to answer the question. I want to have it so if they get it wrong and drive the wrong way that I can use a trigger to respawn them back before the question.

function OnTriggerEnter (Collision : Collider) { transform.localPosition = Vector3(1085,3,944); transform.rotation = Quaternion.identity; transform.Rotate(Vector3.up * 0, Space.World); } How can I have it so I have that on my cube trigger and it'll take my car and not my trigger to that position

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 roamcel · Feb 05, 2012 at 08:09 AM

Your question is not really clear, but I believe that your problem comes from the use of the 'transform' variable.

transform (the reference of the current objects' transform), different from 'Transform' (the object class), indicates the transform property of the object the script is running from.

So if you attach the script to a cube, and type

 transform.Translate(1,0,0);

the cube will translate 1 unit to world right direction.

What you need instead is to acces the 'other' object transform, which is conveniently accessible through the 'collider' parameter that the trigger functions allow.

function OnTriggerEnter (Collision : Collider) function OnTriggerEnter (other : Collider)

inside the function then, you use

 other.transform.Translate(1,0,0);

and this will move the object that entered the collider, rather than the cube the script is attached to!

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 Aram-Azhari · Feb 05, 2012 at 08:22 AM

Add a property to the cube trigger code: public GameObject Car; Then on the triggerEnter code: Car.transform.localPosition = Vector3(1085,3,944); Car.transform.rotation = Quaternion.identity; Car.transform.Rotate(Vector3.up * 0, Space.World); Now save the code, in the Hierarchy select the cube, and then drag and drop your car object into its inspector window (on top of Car property).

This was one way of doing it. The other way is to have your car having a unique Tag. And then use GameObject.FindWithTag("the tag you chose for the car object") in the on trigger to get the car object. So you don't have to drag drop the car object to the cube inspector anymore.

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 Spilker · Feb 07, 2012 at 02:59 AM

public GameObject.FindWithTag("Car");

function OnTriggerEnter (Collision : Collider) { Car.transform.localPosition = Vector3(901.2015,-0.02017058,936.0092); Car.transform.rotation = Quaternion.identity; Car.transform.Rotate(Vector3.up * 90, Space.World); } when I put that in it gives me a unexpected token: Game Object error

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 Aram-Azhari · Feb 07, 2012 at 06:21 AM 0
Share

which line is giving this error? (the line number is written in the console window)

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

6 People are following this question.

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

Related Questions

If trigger hit, spawn it 1 Answer

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

Change skybox at runtime? 2 Answers

Getting audio.PlayOneShot to work 2 Answers

Safe area from enemies 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