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 Tyler 2 · Dec 05, 2010 at 08:28 AM · transformpositionteleport

Transform position?

Hello. I want to make a space shooter like asteroids (where the screen wraps around, so if the player hits an edge, they will go to another place). When I am using transform.position, how can I use the player's current position for two values and have the other one be incorporated into a simple math function? So it would be something like this

transform.position = Vector3(Current X, Current Y, Current Z-30);

Thanks.

Comment
Add comment · Show 1
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 BerggreenDK · Dec 16, 2010 at 11:11 PM 0
Share

Did you read my answer and was it useable or do you still need something to make this work? Please answer by checking the correct answer or provide us with further details.

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by BerggreenDK · Dec 05, 2010 at 08:56 AM

I would do a check for objects where I use the "size of the screen" as margins. These can be found at application start.

Look here: http://unity3d.com/support/documentation/ScriptReference/Screen.html

Now you have the MAX pos for both directions. Then make a simple check on the coords of each object. Are we outside? if we are, then add/subtract the size from the objects pos.

Depending on your "center" position of your camera, you might have to ajust the values a bit, but I expect you to place 0,0,0 in center of screen for this example.

So I globally initiate the width and height and divide by 2 so I have the center position.

void function CheckBorder(Transform o) { if (o.position.x < xHalfScreenSize) { o.position.x += xScreenSize } else // else is important, otherwise you would switch back and forth in same check { if (o.position.x > xHalfScreenSize) { o.position.x -= xScreenSize } }

 if (o.position.y &lt; yHalfScreenSize) { o.position.y += yScreenSize }
 else  // else is important, otherwise you would switch back and forth in same check
 {
    if (o.position.y &gt; yHalfScreenSize) { o.position.y -= yScreenSize }
 }

}

Now you should be able to throw any object into this function.

As you might see, this makes the object "swap" inside visible area, thats not good. So add a little "extra" border to the screen sizes. A good value must be at least the max size of your object. Lets say your largest meteor would be 256 pixels, then just add 256 to the screen sizes, before dividing.

hope this helps.

Comment
Add comment · Show 3 · 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 Proclyon · Dec 05, 2010 at 11:42 AM 0
Share

A fair warning though, when the parameter defined for the measurement is (regardless of the parameter you picked for the job) changed during any part of the game you will get unwanted behaviour unless the exception is caught and dealt with.

avatar image Proclyon · Dec 05, 2010 at 11:42 AM 0
Share

+1: Good answer though, don't get me wrong. Just saying don't start messing with screensize ingame or it gets messed up

avatar image BerggreenDK · Dec 07, 2010 at 06:24 PM 0
Share

Yeah, going from embedded to fullscreen and back or perhaps tilting the screen on touchdevices etc. would need some sort of trigger/exception handling, but I didnt want to make the answer too complicated. One problem at a time. :o) Thanks for thoughts though, no offence taken at all!

avatar image
1

Answer by FLASHDENMARK · Dec 05, 2010 at 12:02 PM

You could also check for collision like so:

var changePosition = false;

function OnControllerColliderHit (hit : ControllerColliderHit) { if(hit.gameObject.tag == "Typewhateveryouwant") // Make sure the object you collide with has the same tag as written. {
changePosition = true; } } function LateUpdate () { if(changePosition) = true { transform.position = Vector3(?,?,?) // Write the position you wanna "respawn" to. } }

Hope that helpes :)

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

No one has followed this question yet.

Related Questions

transform position player teleport 0 Answers

I'm trying to teleport with a key press, but right now they only teleport for one second. How to fix?,With a key press, no OnTriggerEnter, how to teleport the player? 2 Answers

Teleporting Player to a point using box colliders 1 Answer

Making The Hole In A Golf Game 1 Answer

Transform.Position Help 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