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
1
Question by e-bonneville · Jun 06, 2010 at 06:33 PM · camerateleportasteroids

How can I program a 'wrap-screen'?

In Asteriods, if you fall off one side, you'll appear on the other directly reversed from your position. How can I program such a thing?

Would it be as simple as doing a raycast backwards until it hits a collider I would place at the boundries of the camera viewport, and then putting the ship at that point?

Thanks, Elliot B.


Top.js

var bottom : GameObject;

function OnTriggerEnter (other : Collider) { other.gameObject.transform.position.x = bottom.transform.position.x; }

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
3
Best Answer

Answer by Ryder · Jun 06, 2010 at 08:00 PM

I'm a noob in unity, but have done some programming...

Excuse the simplicity of the suggestion (perhaps you are asking a far deeper question than I am perceiving).

What I have done in the past is simply detect the object passing a boundary. You could probably do it with a simple colision trigger, and simply "warp" the object to the opposite side of the screen by changing its location. It should still retain its motion.

Hope this is not syntactically bogus, but you get the idea:

transform.position.x = -512

Example: when the "ship" is leaving the right side of the play area, at the moment it is still half visible, simply reset the X position to the left side of the screen.

The down side to this is you can't see the object leaving on one side and emerging from the other at the same time... but it's not a serious flaw in my experience.

Of course for many objects, like in asteroids, you would probably have the boundary object detect what object triggered it, and then change the position of the object that touched it... this would work for the asteroids as well as the ship. Even "shots" would warp properly if that is what you wanted.

Ryder

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 e-bonneville · Jun 06, 2010 at 09:13 PM 0
Share

That sounds right. However, I being me, I can't program it right. Do you happen to have an example laying around? Or could you look at the code (I'll post it in my Question) and fix it for me?

avatar image e-bonneville · Jun 06, 2010 at 09:14 PM 0
Share

Thanks a lot. ;)

avatar image Ryder · Jun 06, 2010 at 09:54 PM 0
Share

Sorry, I don't :) But your code looks reasonable to my untrained eye.

You could change your code to read:

print("collision detected"); //to be sure the routine is firing other.gameObject.transform.position.x = 100; //test jump

to test that the jump is working at all. (just basic debugging)

avatar image e-bonneville · Jun 07, 2010 at 12:26 AM 0
Share

@Ryder Thanks, that did it. +1 for suggesting obvious solution.

avatar image
-1

Answer by Benjamin 2 · Mar 06, 2011 at 02:13 AM

Where would you put ("collision detected")? And will it work for 3D?

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 Eric5h5 · Mar 06, 2011 at 02:44 AM 0
Share

Don't post comments or questions as answers.

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

Teleport + TrailRenderer = problem 2 Answers

Camera Transform.Position (teleport) 2 Answers

How can I make a character disappear from view from one side to the other? 1 Answer

How to make camera position relative to a specific target. 1 Answer

Camera Following character that teleported 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