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 shadypepe · Feb 21, 2014 at 12:40 AM · dragareaonlyonerigid

Apply DragRigidBody.js to only a certain group of objects and only in a specific area

Hi, new here and very very limited javascript skills. I'm trying to work everything out myself or via tutorials/forums but I'm stuck since a few days here: Is there an easy way to tell the bundled DragRigidBody.js to apply to only a certain group of objects (tagged)? My other question would be if one can limit the area to which the script applies ( I basically want to shoot an obect but not let the user control the thrown object in mid-air). Thanks a lot in advance!

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
0

Answer by robertbu · Feb 21, 2014 at 12:52 AM

Create a new JS script file with a name like 'MyDragRigidbody'. Copy and paste the contents of the DragRigidbody.js script into this new file. You will be using this file in place of the original DragRigidbody.js script.

Insert at line 25:

 if (hit.collider.tag != "WhateverTagYouWant") 
     return;

And below that, you can do your check:

 if (hit.transform.position.y > someValue) 
    return;

I'm not sure how you will define the acceptable area to start dragging. I've done it here by the 'y' value, but you may want something else. Regardless, figure out your check, and just return if the criteria is not met.

Comment
Add comment · Show 3 · 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 shadypepe · Feb 21, 2014 at 02:04 AM 0
Share

Thank you so much, that already helped! I was so confused by the if and then negative thing but thanks, got my head around that ;)

The area thing works as well, the only thing is I need the dragging to stop as soon as the obect is dragged beyond the area that "dragging is allowed" (so when the mouse is kept down during the drag). Do you think you could help me with that as well or is that more complicated? Thanks!

avatar image robertbu · Feb 21, 2014 at 02:36 AM 0
Share

I don't know what you test for 'area' is. But say for example the test was the distance from some point you define at the top of the file. Find this line (line 61 in the original script):

  while (Input.Get$$anonymous$$ouseButton (0))

Change it to:

  while (Input.Get$$anonymous$$ouseButton(0) && Vector3.Distance(centerPointYouDefined, springJoint.transform.position) < someDistance)

$$anonymous$$y guess is you are going to want some other condition, but the idea is to ter$$anonymous$$ate this while loop when the object is outside the area.

avatar image shadypepe · Feb 21, 2014 at 06:48 PM 0
Share

thanks a lot again, this helped me solve it!

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

18 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

Related Questions

Only one animation playing NON-STOP!!? 2 Answers

Accessing one gameobject from many clones 2 Answers

Swapping 2 objects positions when one is dragged into the other 1 Answer

how i can remove character controller drags 1 Answer

Fire hose - Dragging Issue 2 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