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 Rhylvin2015 · Jun 19, 2015 at 06:24 PM · timeframecalculate

How to calculate the amount of Change of Position.Y for a certain amount of time.

Hello, i have a 2d game that could jump from platform to platform. the problem is I have a Roll mechanism that the player could roll. I want to use that roll when the player's Y position change a lot meaning the player jumped or dropped down on a high platform making him roll down on the ground for a realistic feel. I understand my concept completely but I can't seem to make the code.

P.S 1.) Roll is a boolean so if I wanna use it. Ill only write roll = true;

2.)The script is already on the player so this.gameObject.transform.position.y is usable.

Comment
Add comment · Show 4
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 _dns_ · Jun 19, 2015 at 08:19 PM 1
Share

Hi, I would use the velocity of the object. If the velocity is going down and it's magnitude is superior to an amount, then the Roll can be true.

If your object has a rigidbody: use rigidbody.velocity.magnitude to get the "speed" of the object to then compare to a chosen amount/speed. And if rigidbody.velocity.y < 0.0f, this means the object is going down.

If your object doesn't have a rigidbody, you can compute a velocity yourself: store the previous position in a Vector3 (from the previous FixedUpdate or Update) and compute the Vector3 velocity = (currentPosition - oldPosition) / Time.deltaTime;

avatar image Rhylvin2015 · Jun 20, 2015 at 02:02 AM 0
Share

yup you were right sir. um could i have another question. how do i make it so that the player only rolls once?

avatar image _dns_ · Jun 20, 2015 at 02:55 AM 1
Share

Well, it depends on the condition you want to have to allow it to re-roll again, and how you roll it = is it an animation ? Usually it involves a kind of simple state machine = testing and setting Booleans to true/false or/and testing if a certain amount of time has passed...

Set a Boolean to true when you start rolling and set it to false when you want to be able to roll again, maybe when the speed is under a certain amount or when you hit something or start to jump again or all of that :) It's difficult to answer without more details. One general advice is to download the free projects from Unity $$anonymous$$ms on the asset store and check how they do it :)

avatar image Rhylvin2015 · Jun 21, 2015 at 04:53 PM 0
Share

thanks for the answers, you really were helpful to me. God Bless u sir.

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

animation["name"].time is always zero? 3 Answers

How to calculate an average frame rate 3 Answers

Calculate in Seconds not Frames? 2 Answers

vBlank Drift - Locking unity to the vBlank? 1 Answer

Increase/Decrease Over Time, Not Frames 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