Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
2
Question by fulcanmal · Sep 30, 2010 at 08:49 PM · vector3movedirectioncontrollercolliderhit

ControllerColliderHit.moveDirection and ControllerColliderHit.normal

I am trying to understand what the Vector3 values represent in terms of moveDirection.

As described by the API reference moveDirection is 'approximately the direction from the center of the capsule to the point we touch'

But how is a "direction" represented numerically? Is the value a particular degree of rotation, a distance between the object, or something else I haven't considered?

This question is the result of my attempt to study the code of the Unity 2D Side Scroller tutorial. In particular, this line of code:

function OnControllerColliderHit (hit : ControllerColliderHit){ if (hit.moveDirection.y > 0.01) return;

if (hit.moveDirection.y < -0.9 && hit.normal.y > 0.9) { activePlatform = hit.collider.transform;
}

}

If I understand this correctly based on the context, this means that the first if statement will execute if the object collided with is above the game object (in this case the CharacterController) thus exiting the function without effect via the return command. The second if statement will execute if the object collided with is below the game object and at a certain angle. However, as I said above, I am unclear as to how these values represent direction and angle. What precisely would be the difference between a moveDirection.y value of 0.01, and a moveDirection.y value of 10? Likewise what does the value of normal represent? Is 0.9 a 90 degree angle?

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

Answer by skovacs1 · Sep 30, 2010 at 09:28 PM

A Vector3 is a struct of 3 floating point numbers.

Vector math is the same as it was when you first used a piece of graph paper back in school and is only different in 3D by the addition of another axis. Angles really have nothing to do with it for all that it matters.

When used to represent a direction, each number represents a delta along a coordinate system axis. The length of the diagonal from (0,0,0) to the point indicated by those three deltas is called the magnitude of the vector. A normalized vector is a vector with a magnitude of 1.

For example, if something is at the origin of the coordinate system (0,0,0) and something else were at (1,2,3), it would be 1 unit along the coordinate system's x axis, 2 units along the coordinate system's y axis and 3 units along the coordinate system's z axis. (1,2,3) is the vector representing the movement needed to move from the origin to that position. The magnitude of that movement is 3.741657, the length of the diagonal from the origin to that point.

The directions provided by your ControllerColliderHit are normalized.

In your code: If the collision point is at a direction that is no more 0.01 units along the world y axis (generally above), it will return. If the collision point is at a direction less than -0.9 units along the world y axis (mostly completely beneath) and the normal of the surface hit is pointing in a direction that is greater than 0.9 on the world y axis (almost completely up), the active platform is set to the transform whose collider was hit.

What this means is that if you hit something that is not beneath you, exit early and if you hit something that is mostly beneath you and the surface is pointing mostly up, that becomes the active platform.

Comment
Add comment · Show 2 · 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 · Sep 30, 2010 at 11:16 PM 0
Share

Fantastic answer.

avatar image fulcanmal · Oct 01, 2010 at 12:06 AM 0
Share

This was excellent, the most helpful response to any Unity question I've ever received.

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

Raycast in Direction of Input Movement 0 Answers

How to get this object to move 2 Answers

moving between two points over time 1 Answer

Sum Of Two Motions? 0 Answers

Distance won't work 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