Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 kfchristian15 · Feb 01, 2015 at 05:25 PM · c#transformscriptingbasicstransform.positionteleport

how to make a bolt collision teleport player to where the collision happened

I want to make my player have something like a teleport gun, where he fires bolts and whatever they hit, the player teleports to. I have a player that shoots bolts right now and I'm wondering how to code the teleport part. This script teleports the bolt shots back to the player once they hit (though they are disabled), how do I make the player teleport to where the bolt shots hit?

public GameObject hit; public GameObject player; Vector3 spawnPoint;

 void Start () 
 {
     GameObject spawnObject = player;
     spawnPoint = spawnObject.transform.position;
 }
 void OnCollisionEnter (Collision collision) {
     if (collision.gameObject.tag == "ground") 
     {
         Instantiate (hit, transform.position, transform.rotation);
         transform.position = spawnPoint;
         gameObject.active=false;
     }
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
0
Best Answer

Answer by hav_ngs_ru · Feb 02, 2015 at 09:23 PM

 // bolt script
    void OnCollisionEnter(Collision.collision) {
      ...
      if (collision.gameObject.tag == "ground") {
         SetActive(false);
         player.SendMessage("TeleportTo", transform.position);
         ...
      }
      ...
    }
 
 // player script
    public void TeleportTo(Vector3 teleportPoint) {
       transform.position = teleportPoint;
    }
Comment
Add comment · Show 5 · 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 kfchristian15 · Feb 03, 2015 at 03:45 AM 0
Share

I tried this and I'm getting an error "the name spawnObject does not exist in the current context"

avatar image hav_ngs_ru · Feb 03, 2015 at 08:32 AM 0
Share

fixed it. player.Send$$anonymous$$essage(...)

avatar image kfchristian15 · Feb 03, 2015 at 03:40 PM 0
Share

That works, thank you!

avatar image kfchristian15 · Feb 03, 2015 at 06:01 PM 0
Share

is there an easy way to slightly offset the teleport, because sometimes I get stuck in the material I teleport to. Thanks for your answer though, it was just what I was looking for.

avatar image hav_ngs_ru · Feb 04, 2015 at 08:16 AM 0
Share
 player.Send$$anonymous$$essage("TeleportTo", transform.position + (player.transform.position - transform.position)*offset);

declare public float offset in bolt script and ajust its value in inspector

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

how would the code be for the son of my game object to teleport to position 0.36,0,0 in relation to the center of my game object? 1 Answer

Multiple Cars not working 1 Answer

How Do I Give Two Objects the Same Transform? 1 Answer

Pokemon Type Teleport not working. (transform.position) 1 Answer

Only Teleports Player Every Once in While 2 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