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 ThePositiveMoxie · Sep 23, 2012 at 02:11 AM · positiontouchoffsetlocalworld

Touch position off from real position?

Hello, I've been working on a new project... never had this issue before though. I'm using EasyTouch, but I've run into this with other things. As it is the same Asset I used in my last game with no problems.

I made a variable for the sake of recording it's touch position. I have a character, and I want to be able to have it change directions, if you touch on the left side or the ride side of him. Except my character is at around -25 units on the X axis. When I touch around him, it's such a huge different. Around position 600 units on the X axis.

Does anyone know what might be causing such a large offset?

It's not in the code, because I only have a few lines... only asking if gesture.position.x < the game objects position. or greater.

Edit: Here is the code I used (attached to the camera), I have also noticed... the character twitches and can't move past a certain point (it auto-flips him back around).

 var mainCharacter : exSpriteAnimation;
 var mainCharacterBase : exSprite;
 var mainCharacterObject : GameObject;
 var touchx : float;
 var touchy : float;
 
 function Start()
 {
     mainCharacter.Play("idle");
 
 }
 
 function On_TouchStart(gesture:Gesture)
 {
     // Play "walk right" animation if touch at ground level
     if(gesture.position.x > mainCharacterObject.transform.position.x){
             
             mainCharacter.Play("walk");
             mainCharacterObject.transform.position.y = mainCharacterObject.transform.position.y - 8;
             mainCharacterObject.transform.eulerAngles.y = 0;
             
     }
     
     // Play "walk right" animation if touch at ground level
     if(gesture.position.x < mainCharacterObject.transform.position.x){
 
             mainCharacter.Play("walk");
             mainCharacterObject.transform.position.y = mainCharacterObject.transform.position.y - 8;
             mainCharacterObject.transform.eulerAngles.y = 180;
             
     }
     
 }
 
 
 function On_TouchDown(gesture:Gesture)
 {
     // Translate "walk right" animation if touch at ground level
     if(gesture.position.x > mainCharacterObject.transform.position.x){
             mainCharacterObject.transform.Translate(2,0,0);
             mainCharacterObject.transform.eulerAngles.y = 0;
             
     }
     
     // Translate "walk right" animation if touch at ground level
     if(gesture.position.x < mainCharacterObject.transform.position.x){
             mainCharacterObject.transform.Translate(2,0,0);
             mainCharacterObject.transform.eulerAngles.y = 180;
             
     }
     
 }
 
 
 function On_TouchUp(gesture:Gesture)
 {
     mainCharacter.Play("idle");
     mainCharacterObject.transform.position.y = mainCharacterObject.transform.position.y + 8;
 
 }
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 Bunny83 · Sep 23, 2012 at 03:51 AM

I never used EasyTouch, but it seems the touch position is, like almost always, in screen coordinates. As in the first code example on this page you can see he uses `cam.ScreenToWorldPoint`. Keep in mind that would only work with an orthographic camera. With a perspective camera you need to use a raycast to project the 2d point into world space.

A common way to project a screen point to world space for a 2d or 2.5d game is to use a Plane

See the edit in my answer on this question.

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 ThePositiveMoxie · Sep 23, 2012 at 04:10 AM 0
Share

Thank you, weird how I never had to worry about that stuff before. Worked right out of the box in my first game. Though now I it works, but I have to figure out how to get my character working in the same coordinates as far as positioning. I did always use Orthographic though. As this is a 2D game, and so was the last.

I think I can take this and figure it out now. Thank you!

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

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

GameObject's local position without parent 1 Answer

How to define a position local to an object? 2 Answers

Finding Position based on a local perspective 1 Answer

Move object on local axis instead of world axis after rotation 0 Answers

Why does the object alignment only work when the object isn't rotated? 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