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 02, 2010 at 02:28 PM · 2d-platformerlogic

Transform.position: Moving Platform Support Logic

I'm trying to understand the code for the moving platform support in the Unity side-scroller tutorial.

The relevant code 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;

As I understand it the reason this code exists is because the character controller will not automatically react to a moving collider.

So basically we are subtracted the player's position form the active platform's position in World Space. My understanding is that this should move the character along with the platform.

If the platform is at say (0,1,0) and the player is standing on top of it at (0,2,0) then move distance should equal (0,-1,0) correct? This would move the player's position downward just by standing on the platform.

Here is where I get lost in the logic:

If the platform moves up to (0,2,0) and the player is at (0,2,0) then moveDistance = 0. The purpose of the code as I understand it is to move the player, so his World Space coordinate wouldn't automatically move, and thus be (0,2,0) at this point.

My question is simply this: How does this move the player relative to the moving platform?

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

Answer by Loius · Oct 03, 2010 at 04:00 PM

Egad those variable names they are so long.

Alright, going into the function we have:

transform.position = (0,2,0)
activePlatform.position = (0,1,0)

then from those we know that

activeLocalPlatformPoint = (0,1,0)
activeGlobalPlatformPoint = (0,2,0) // I think. :p

Then we move the platform to

activePlatform.position = (0,2,0)

and run the code:

var newGlobalPlatformPoint = activePlatform.TransformPoint(activeLocalPlatformPoint);
// ((0,2,0)(no rotation)).TransformPoint( (0,1,0) ) = (0,3,0)
// basically point addition when there's no rotation happening.
activeLocalPlatformPoint = activePlatform.InverseTransformPoint (transform.position);
// alpp = (0,2,0).ITP( (0,2,0) ) = (0,0,0)
// finding the relative position of player to platform
var moveDistance = (newGlobalPlatformPoint - activeGlobalPlatformPoint);
// (0,3,0) - (0,2,0) = (0,1,0) 
transform.position = transform.position + moveDistance;
// moveDistance = (0,1,0)
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 fulcanmal · Oct 04, 2010 at 06:29 PM 0
Share

You have activeLPP equaling (0,0,0) when it is set, but equaling (0,1,0) when newGPP is set. When did it pick up the extra y coordinate?

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

Change 2D box collider Y values but how offset stay on same position and adjust their values. 0 Answers

How to add knockback when player hit enemy 2D Platformer 0 Answers

Sprite turning around repeatedly against a wall. How to have "Wallslide" flip sprite? 0 Answers

Developing a 2D level Editor for a 2D game 2 Answers

2d Platform tutorial problem 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