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 Yarbius · Jul 09, 2014 at 05:16 PM · sprite2d-platformercoordinate-system

move sprites in side scrolling 2d game in screen coordinates

I am trying to make the enemies in my side scrolling 2d game move in absolute screen coordinates instead of world coordinates I have their waypoints stored in screen coordinates and use the following line of code to move them:

         // Move the enemy toward its waypoint
         transform.position = Vector3.MoveTowards
                                 (transform.position, 
                                  mainCamera.camera.ViewportToWorldPoint(nextWaypoint), 
                                  currentSpeed * Time.deltaTime);



The problem I am having is that, since the actual movement happens in world space, the enemies are fighting the screen scrolling so their speeds are messed up and their target position moves away from the screen location. I want them to move as if they are on a static plane and not a scrolling map (They are aerial) I have googled up a storm but have not found a way.

My problem is probably mindset, I am used to XNA where I would create worldToScreen() and ScreenToWorld() methods and then use them interchangeably depending on the context of the problem being solved.

Thanks for any help

Mike

Comment
Add comment · Show 2
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 robertbu · Jul 10, 2014 at 04:24 AM 0
Share

I'm pretty good at figure out these kinds of problems. I read your question when it first came in the list and again just now, and I'm having difficulty understanding your problem. Can you post a video of the 'speeds are messed up'?

I want them to move as if they are on a static plane and not a scrolling map

As long as the speed is high enough to overcome the scrolling and if the object is at the waypoint, then this should be happening.

avatar image Yarbius · Jul 10, 2014 at 04:36 PM 0
Share

I thought about this issue last night and I think I have a solution. It is a side scroller ($$anonymous$$oon Patrol clone as a learning project) and the areal enemies are my issue. I started with a waypoint system in world coordinates but they would get left behind if the player sped up.

I changed the coordinate system to use ViewPortToWorld() and that helped but they still fight the scroll speed of the game because the target location moves after the first frame.

I am going to try recalculating the world coordinate they are headed to each frame and then compensate for the variable scroll speed of the player by adding the players speed to their speed each frame.

0 Replies

· Add your reply
  • Sort: 

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

2 People are following this question.

avatar image avatar image

Related Questions

Poor quality sprite 2D game 3 Answers

How to Instatiate an empty spriteObject and be able to draw a image/sprite like you would in paint? 0 Answers

How to animate a 2d character 1 Answer

Changing a Sprite when Collision occurs 2 Answers

How do i change the sprite on a sprite renderer without changing the size? 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