Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 stalyan77 · Jul 27, 2015 at 09:40 AM · raycastpositionisometricorigintransformpoint

Isometric Raycast: misplaced origin & not updating position with TransformPoint

Hi guys,

I'm sure I'm missing something simple but I can't get this to work.

I have a player cube in an orthographic view. When the player moves or jumps, I want to cast 4 rays on each vertex on the contrary face to the movement. I'm first testing with one raycast. I have the vertex positions of the collider in local space in a function called Calcpositions().

The problem is: if I transform the local position of one collider vertex with TransformPoint, the position is like half the height of the cube too much up. I don't understand why this is being added.

On the contrary, if I comment the code line that transforms the local position of any vertex to a global position, then the ray is properly casted, but only when I hit play. As soon as I move the cube, the ray will stay in its position but won't follow and update with the movement of the cube.

I've tried adding and subtracting transform.position to both local and global position of any vertex, but the ray is yet misplaced.

I attach a screenshot so you can see how the ray looks like on the Scene viewer (in the Game view it would seem as if the ray has the origin in the proper vertex position -in the example v3FrontTopLeft- but on the scene view it can be seen this is not true).

1) Why the ray does not update its position in local scale I understand, as the vertex positions are always the same ones no matter if the cube player updates its position. How I can do to properly update its movement and follow the player cube transform without using TransformPoint? or that's not possible? (i've tried to add transform.position to the vertex position but it doesn't work as it alters the original coordinates and the vertexs are again misplaced as when using TransformPoint).

2)If I use TransformPoint, why the vertex coordinates are half what they should be?

3) How can I cast the ray from the proper vertex position as it happens when I use the local scale coordinates (but then it does not follow the cube player movement), and at the same time update its position and follow the player cube as when I use TransformPoint or I add the transform.position (but the the ray is misplace too up but half the height of the cube it seems)?

Any hint or help on this is welcome, i've been stuck for a couple of days now.

  void Update()
     {
         transform.Translate(Vector3.down * -gravity * Time.deltaTime);
              
         KeyReleaseHandler();
         GetKeyInput();
         MovePlayer();
         CalcPositons();
         
     }
 
 public void CalcPositons(){
     
         Vector3 v3Center = bounds.center;
         Vector3 v3Extents = bounds.extents;
 
         Vector3 v3FrontTopLeft;
         Vector3 v3FrontTopRight;
         Vector3 v3FrontBottomLeft;
         Vector3 v3FrontBottomRight;
         Vector3 v3BackTopLeft;
         Vector3 v3BackTopRight;
         Vector3 v3BackBottomLeft;
         Vector3 v3BackBottomRight; 
 
         
         v3FrontTopLeft     = new Vector3(v3Center.x - v3Extents.x, v3Center.y + v3Extents.y, v3Center.z - v3Extents.z);  // Front top left corner
         v3FrontTopRight    = new Vector3(v3Center.x + v3Extents.x, v3Center.y + v3Extents.y, v3Center.z - v3Extents.z);  // Front top right corner
         v3FrontBottomLeft  = new Vector3(v3Center.x - v3Extents.x, v3Center.y - v3Extents.y, v3Center.z - v3Extents.z);  // Front bottom left corner
         v3FrontBottomRight = new Vector3(v3Center.x + v3Extents.x, v3Center.y - v3Extents.y, v3Center.z - v3Extents.z);  // Front bottom right corner
         v3BackTopLeft      = new Vector3(v3Center.x - v3Extents.x, v3Center.y + v3Extents.y, v3Center.z + v3Extents.z);  // Back top left corner
         v3BackTopRight     = new Vector3(v3Center.x + v3Extents.x, v3Center.y + v3Extents.y, v3Center.z + v3Extents.z);  // Back top right corner
         v3BackBottomLeft   = new Vector3(v3Center.x - v3Extents.x, v3Center.y - v3Extents.y, v3Center.z + v3Extents.z);  // Back bottom left corner
         v3BackBottomRight  = new Vector3(v3Center.x + v3Extents.x, v3Center.y - v3Extents.y, v3Center.z + v3Extents.z);  // Back bottom right corner
         
         Debug.Log (bounds.center);
         Debug.Log (bounds.extents);
 
         v3FrontTopLeft     = transform.TransformPoint(v3FrontTopLeft);
         v3FrontTopRight    = transform.TransformPoint(v3FrontTopRight);
         v3FrontBottomLeft  = transform.TransformPoint(v3FrontBottomLeft);
         v3FrontBottomRight = transform.TransformPoint(v3FrontBottomRight);
         v3BackTopLeft      = transform.TransformPoint(v3BackTopLeft);
         v3BackTopRight     = transform.TransformPoint(v3BackTopRight);
         v3BackBottomLeft   = transform.TransformPoint(v3BackBottomLeft);
         v3BackBottomRight  = transform.TransformPoint(v3BackBottomRight);  
 
 
         Debug.DrawRay(v3FrontTopLeft, Vector3.up *1.5f, Color.red);
     }

PS. Notice I'm only using Debug.DrawRay for testing purposes without any Physics.Raycast(v3FrontTopLeft, transform.up, out hit, 10f); I will use it once I get this right.

alt text


raycast-isometric-wrong-position-or-doesnt-update.jpg (203.6 kB)
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

Answer by stalyan77 · Aug 21, 2015 at 10:33 PM

This was finally solved.

I was using Bounds.center, that returns coords in global space, instead of Collider.bounds.center (and extents), that returns coords in local space,. I then used transform.TransformPoint and the rays are properly positioned in global space =)

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

2 People are following this question.

avatar image avatar image

Related Questions

Fire weapon from turret to mouse position (3D Isometric shooter) 1 Answer

Changing position of a RayCast 1 Answer

Move player with mouse help 0 Answers

camera.ScreenPointToRay always has same origin... 1 Answer

RayCast relative to camera stays in 1 place. 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