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 /
This question was closed May 06, 2015 at 07:48 AM by alok-kr-029 for the following reason:

solved

avatar image
0
Question by alok-kr-029 · Mar 20, 2015 at 07:42 AM · dragmousedrag

Drag a object along curves

Hi I want to drag an 2d object along a curvy 2dpath
if the player drag in right path the object gets drag or else not , check the file attached

what I tried is on mouse drag I raycast through the object and checked if it hit the path then move else not but its not working smoothly and the object freezes

 RaycastHit2D hits;![alt text][1]
     hits = Physics2D.Raycast(transform.position, -Vector3.back, 10000f,7) ;
     if(hits.collider != null && hits.collider.tag== "path" )
     {
         Lastpos = hits.point;
         Debug.DrawRay(transform.position,-Vector3.back,Color.green,Time.deltaTime*10);
         print (hits.collider);
         Vector3 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
         transform.position= new Vector3(pos.x,pos.y,-0.1419618f);

     }

 

.

[1]: /storage/temp/42981-pathline.png

pathline.png (119.1 kB)
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

  • Sort: 
avatar image
0

Answer by Utamaru · Mar 20, 2015 at 09:36 AM

Try to set a path as array of Vector3s, and every time mouse changes position, find closest point from array to your mouse's position. If its smaller then some constant allowable value - move your object, otherwise don't do anything.

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 alok-kr-029 · Mar 20, 2015 at 09:55 AM 0
Share

but my levels will be generated dynamcally .. how can i set an static path vector

Follow this Question

Answers Answers and Comments

22 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

Related Questions

How will i drag my object with out object disturb? 0 Answers

Collision with object using MouseDrag 1 Answer

How do i disable my buttons while dragging ScrollRect? 0 Answers

How will i drag my object only x and y axis? 2 Answers

How to apply offset to touch position when dragging object 4 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