Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 eriknastesjo · Aug 16, 2018 at 08:00 PM · 2djumpangledragrelease

Drag and jump mechanics?

I'm new to Unity and have been searching for a tutorial for a 2D game where one 1. drags (with mouse or finger) and 2. releases. On release the player jumps towards a certain point in a certain speed, depending on angle and reach of the drag. Hope this description makes sense. Thank you for reply! :)

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

2 Replies

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

Answer by RustyCrow · Aug 16, 2018 at 10:23 PM

unity 2d trajectory prediction <-- this is the keywords you need to goggle to get the knowledge needed. It is a complicated enough question to the point where getting code that exactly fits your criteria is going to be hard to find or atlaset understand for someone new(people getting paid to make this :P), or if you are very lucky maybe a kind soul can help you out with som free code.

I would say understand the math behind what you are asking is the Key to the problem, once you understand the Equation(formula ?) you find/plug the values(angle and force) you need from the mouse/finger.

i hope i dont come off as a a**hole i just dont think people gonna give you free code and if that was what you were expectation this place isnet going to be very helpful.

I hope this will help you get on the right track with your problem and pleas dont get scared of asking question, just keep in mind this is a place to solve problems together, not can someone make this game, mechanic or whatever for me. Its hard to ask/formulate a good question (i know to well :D)

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 eriknastesjo · Aug 17, 2018 at 04:25 AM 0
Share

No worry, thank you for reply! No, of course I understand and I wouldn't ask someone to work for free. I thought maybe there was a shortcut similar to beginners lessons of "2D Game $$anonymous$$it" that one could get into really easily. Thanks again :)

avatar image
1

Answer by rainChu · Aug 16, 2018 at 11:11 PM

Drawing a dotted line predicting the player's jump trajectory is complicated, but actually getting those physics to work aren't that picky. When the user presses and holds, mark the x,y coordinates that the click started. Each frame, draw a straight line from there to the current cursor location. When the user lets go, you can apply an impulse using the physics engine based on the starting position and where the cursor currently is. Take a vector representing the distance the cursor is currently offset from the starting point. Its magnitude is the force the user wants to jump with. Multiply it by some constant factor to adjust the power of jumping in general. You can then pass this vector to the RigidBody or RigidBody2D using the AddForce method. Be sure to set the force type to Impulse, or it won't behave as expected.


For 3D physics systems: https://docs.unity3d.com/ScriptReference/Rigidbody.AddForce.html

For 2D physics system: https://docs.unity3d.com/ScriptReference/Rigidbody2D.AddForce.html

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

186 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Instantiated prefab changes gravitational speed when dragged? 0 Answers

Finding the angle between 2 clicked points 2 Answers

2D GunPivot Bug 1 Answer

[2D Mode] Trying to make a sprite dragable 0 Answers

Why does my 2d player stick to the floor when he lands? 0 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