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 fulcanmal · Oct 04, 2010 at 01:49 AM · transformpoint2d-tutorial

TransformPoint and InverseTransformPoint: Moving Platform Logic

I'm studying the code of the Unity 2D sidescroller and am having difficulty understanding the logic behind the API function TransformPoint. I posted a similar question before, and while the answer received lead me to understanding a great deal more, I'm still not quite there yet.

The relevant code attached to the main character is as follows:

var newGlobalPlatformPoint = activePlatform.TransformPoint(activeLocalPlatformPoint);
activeLocalPlatformPoint = activePlatform.InverseTransformPoint (transform.position);
activeGlobalPlatformPoint = transform.position;
var moveDistance = (newGlobalPlatformPoint - activeGlobalPlatformPoint);
transform.position = transform.position + moveDistance;

What precisely is TransformPoint doing here? The reference says that it transforms from local to world space. But transform.position is already in world space coordinates according to the API reference, and activeGlobalPlatform point is set to the transform of the main character.

So couldn't you just code the following:

moveDistance = (activePlatform.transform.position - transform.position);

Also, subtracting Vector3 values subtracts all axes correct? So if the player is standing on the edge of the platform at (1,2,0) and the platform is beneath him at (2,2,0), wouldn't this move the player horizontally each frame? I'm more than happy with any links to reference pages that I somehow missed. I'm looking for a thorough explanation of these functions or simply for someone to point out some key obvious thing that I've missed.

Perhaps there is something about the Transform class in general, and World and Local space that I am missing.

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 Jesse Anders · Oct 04, 2010 at 04:51 AM

What precisely is TransformPoint doing here? The reference says that it transforms from local to world space. But transform.position is already in world space coordinates according to the API reference, and activeGlobalPlatform point is set to the transform of the main character.

Right, but TransformPoint() is never applied to transform.position or activeGlobalPlatformPoint.

So couldn't you just code the following:

moveDistance = (activePlatform.transform.position - transform.position);

activePlatform.position and activePlatform.TransformPoint(activeLocalPlatformPoint) are only the same if activeLocalPlatformPoint is the zero vector, which won't necessarily be the case. So no, that wouldn't be equivalent in general.

Also, subtracting Vector3 values subtracts all axes correct?

Correct - it is an element-wise subtraction. That is:

(x1, y1, z1) - (x2, y2, z2) = (x1 - x2, y1 - y2, z1 - z2)

Is the code you posted actual code from the tutorial? I ask because there's at least one syntax error (missing semicolon, which I assume is a syntax error in UnityScript), and also because there seems to be some redundant and/or out-of-place code there.

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 fulcanmal · Oct 04, 2010 at 01:40 PM 0
Share

Ah, right. Sorry. Edited. I simply didn't grab the semicolon when I copied, and accidentally copied two lines twice.

avatar image fulcanmal · Oct 04, 2010 at 01:45 PM 0
Share

What do you mean by 'the zero vector'?

avatar image Jesse Anders · Oct 04, 2010 at 03:38 PM 0
Share

The 'zero vector' is just the vector (0, 0, 0). (Or however many zeros, depending on dimension.)

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

TransformPoint and InverseTransformPoint 2 Answers

vertex[i] TransformPoint command not working 1 Answer

ApplyJumping() Logic Problem 1 Answer

Transform.TransformPoint 2 Answers

TransformPoint returns wrong points? 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