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
1
Question by HiPhish · Dec 10, 2010 at 10:52 PM · 2d-platformerbeginneroperator

"someValue = anotherValue > 0.1" What does this mean?

I have been trying to understand the PlatformerController script from the 2D platformer tutorial and ran into this line: movement.isMoving = Mathf.Abs (h) > 0.1;

What exactly does this mean? I can't find any specific information on this kind of syntax.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by skovacs1 · Dec 10, 2010 at 10:59 PM

It's quite simple:

= is the assignment operator.

movement.isMoving = Something sets the value of movement.isMoving to the value of Something. movement.isMoving is a bool value, meaning that it is either true or false and as such Something must be a boolean value.

> is the greater than operator.

Mathf.Abs(h) > 0.1 compares the values of Mathf.Abs(h) and 0.1 and returns the boolean value of whether Mathf.Abs(h) is larger than 0.1.

As a result, movement.isMoving is set to the boolean value indicating whether Mathf.Abs(h) is greater than 0.1.

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
avatar image
3
Best Answer

Answer by Statement · Dec 10, 2010 at 11:17 PM

Short version:

someValue = anotherValue > 0.1 What does this mean?

It means that someValue become true if anotherValue is greater than 0.1, otherwise false.

if (anotherValue > 0.1)
{
    someValue = true;
}
else
{
    someValue = false;
}


Long version:

Mathf.Abs is a function that returns the ABSolute value of the argument passed in.

The absolute value is a number value where you simply remove the negative sign.

Examples:

  • Mathf.Abs ( -3 ) return 3.
  • Mathf.Abs ( 3 ) also return 3.

The expression is formed such as "boolean = a > b". a is Mathf.Abs( h ) and b is 0.1. If a is greater than b, then the expression evaluate to true. Otherwise false.

The sign > is a relational operator and is very common in programming.

In short:

  • movement.isMoving = true if h is greater than 0.1 or smaller than -0.1.
  • movement.isMoving = false if h is between 0.1 and -0.1.

What h is, I have no clue. Probably height from ground. It's a bad name for a variable and I haven't seen the tutorial.

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 HiPhish · Dec 11, 2010 at 03:15 PM 0
Share

Yes, that's it. i kno what mathf.Abs() does (I am a mathematician after all), but i did not understand the first part. thank you very much for the "if ... then ... else ..." explanation, I fully understand now.

avatar image
1
Best Answer

Answer by bjarnefisker · Dec 10, 2010 at 10:56 PM

"Mathf.Abs (h) > 0.1" is a condition that returns either true or false. Mathf.abs returns the absolute value of the input (meaning if the input is -5 it returns 5). If Mathf.Abs (h) is larger than 0.1 the condition is true, otherwise it is false.

The "movement.isMoving =" part in front of it just sets the isMoving property to the returned value of the condition.

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

No one has followed this question yet.

Related Questions

2D character gets stuck when falling 1 Answer

Is there a JavaScript "Between X and Y values" Operator? 1 Answer

How to detect sprite in player's position (2D Platformer Game) And get it t do something 2 Answers

Trouble with tilemaps as prefabs for 2D plattformer 1 Answer

Should I script my own Physics2D Platformer Character Controller just like in the Unity's Live Session? 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