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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
1
Question by buttholejohnson · Nov 16, 2014 at 10:07 PM · transform2d-platformerloopteleport

Cannot use triggers to teleport an object?

This is my script:

 using UnityEngine;
 using System.Collections;
 
 public class screenbottom : MonoBehaviour {
 
 
 
     
 
     void OnTriggerEnter(Collider2D col)
     {
         if(col.gameObject.tag == "screenbottom")
         {
             transform.position (GameObject.FindWithTag ("screentop"));
         }
     }
 
 }

The end goal is to enable an object to fall off the bottom of the screen and continue on through to coming back down from the top infinitely. I have set 'screenbottom' and 'screentop' as 'is Trigger', given them both rigidbody2d and coinciding tags. I cannot imagine why this isn't working but I am new to much of this. Perhaps using entering triggers is not the best idea in the first place? Due to the specificness of using one spawn-point, I can't even imagine how one would expand on this script to allow for the players position to still continue forwards while falling. Any help is super appreciated.

Comment
Add comment · Show 5
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 buttholejohnson · Nov 17, 2014 at 01:14 AM 0
Share

Awesome that's definitely gotta be it, the error I was getting before was almost exactly what you said- but now I am still getting one exception: " The type or namespace name `Gameobject' could not be found. Are you missing a using directive or an assembly reference? " And at the risk of sounding too ignorant, in the code you gave me it is still assumed that the standard C# initialization lines,

 using UnityEngine;
 using System.Collections;
 public class screenbottom : $$anonymous$$onoBehaviour {
  

are still to be included at the top? The only other thing I could think of is, this script is supposed to be attached to a rigidbody2d game object tagged 'Brick'- now that shouldn't be in the code now should it?

avatar image rob5300 · Nov 17, 2014 at 09:46 AM 1
Share

I'm sorry about that, i have changed my answer to be correct, and it should be easy to just copy and use! Just comment again if there is an issue!

avatar image buttholejohnson · Nov 17, 2014 at 03:39 PM 0
Share

Holy cow that works like a charm, and using the editor to add the transform in really makes the code modular and easy to use. Now I can dissect it and start doing all kinds of fun things. Hope to be a useful member of the community sometime soon here! I posted the solution any other forums that I asked this on so that the solution is out there.

Also I found that using linear drag seems to be an appropriate way of capping the y velocity of the object from having it's speed increase infinitely.

Cheers!

P.s. and sorry moderators for my accidentally trying to respond with an answer ins$$anonymous$$d of a comment again!

avatar image buttholejohnson · Nov 17, 2014 at 03:43 PM 0
Share

and I will delete this comment as soon as someone tells me this, but how do I give rob5300 more $$anonymous$$arma points or whatever it is for the awesome answer? He deserves it and I am apparently inept!

avatar image Bunny83 · Nov 17, 2014 at 03:48 PM 1
Share

@buttholejohnson:
If you want to tick an answer as solution, just click the checkmark:
Tick an answer

You can't upvote his answer since you don't have enough karma yourself. You need at least 15 karma to vote. This is to prevent spam accounts to push each other.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by rob5300 · Nov 16, 2014 at 10:49 PM

You are trying to use transform.position as a method which doesn't exist.

To change the position of the game object that this script is connected to that object should be done like this:

 using UnityEngine;
 using System.Collections;
 
 public class screenbottom : MonoBehaviour {
     //This script must be attached to your player that moves.
 
     public Transform screentop;
     //This is a public Transform, soo we can assign this object the transform of the screentop
     //object in the editor, making it much easier to change!
 
     void OnTriggerEnter2D(Collider2D col) {
     //This needs to be OnTriggerEnter2D as we are using 2D colliders

         if (col.gameObject.tag == "screenbottom") {
             Debug.Log("Screen bottom found, moving position to y: " + screentop.position.y);
             //Here we set the y in the transform to the y of the screentop object, thus
             //making sure the character can still move along the x axis (soo we set the x as what it already was to get that behaviour)
             transform.position = new Vector2(transform.position.x, screentop.position.y);
         }
     }
 
 }

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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Change transform.position.y in a loop 1 Answer

transform.position sends object to wrong position 1 Answer

transform position player teleport 0 Answers

Transform position? 2 Answers

Simplist way to rotate camera 180degrees on trigger? 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