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 oktemre · Feb 02, 2014 at 10:02 PM · 2d2d-physicsjointshingejoint

How to give a direction to a hook?

Hi,

I'm very new to Unity and have a question for my school project.

At the top of my Unity 2D scene, there is a hook which needs to have a natural swing left to right. I tried to handle this by adding a hingeJoint to the top of the hook and then applying a velocity to rigidbody2D.

alt text

My problem is sending the hook to the down when played clicked on the space button on the keyboard. Because, the hook is always swinging, when the space button has clicked, it should go to the correct direction depending on the looking direction of the hook and then should come back after touching to the end of the camera view.

I've spent hours on internet in order to find a method to determine correct vector to go down and then go up but all of the examples I could found were about calculating the vector between two known points. In this scenario, I don't have the direction point but only the angle of the transform.

Any help will be appreciated.

Another point: At the moment, when player has clicked on the space button, I am disabling the hingeJoint and converting the body to a kinematic object in order to be able to change the location of the hook to the down. I also appreciate if you have another idea about this part.

screen shot 2014-02-02 at 23.45.25.png (56.2 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

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

Answer by robertbu · Feb 02, 2014 at 10:05 PM

How you do this will depend on how you want to move the hook. The world direction will be 'transform.up' for up direction and '-transform.up' for down direction. These can be used for adding force for example. Or you can use Transform.Translate() which, but default, takes local coordinates. So you can move it up by:

 transform.Translate(0.0, speed * Time.deltaTime * direction, 0.0);

...where 'direction' is 1 for up and -1 for down.

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 oktemre · Feb 02, 2014 at 10:09 PM 0
Share

Hi,

Thanks for the quick answer. I want the hook to go down of the screen but with an angle and the angle need to be the angle of the hook (it always swings and it should go down with the angle of the moment which player clicked on the space button).

Check this video as an example: Video

avatar image robertbu · Feb 02, 2014 at 10:15 PM 0
Share

"and it should go down with the angle of the moment"

And that is what the Transform.Translate() does that I outlined in my answer. Alternately you can do something like:

 transform.position += transform.up * speed * direction * Time.deltaTime;

Note I'm assu$$anonymous$$g the hook is authored so that the bottom of the hook is looking at negative 'y' when the rotation is (0,0,0). If you've constructed the hook so that the hook portion looks at positive 'z' ins$$anonymous$$d, change the 'transform.up' to 'transform.forward', and you would use the 'z' parameter in the Translate().

avatar image oktemre · Feb 02, 2014 at 10:23 PM 0
Share

Worked like a charm. Thanks :)

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

Wheel Friction Curve in 2d 0 Answers

2D Physics: How to have a character "grab" onto wall with hand 0 Answers

HingeJoint2D.GetReactionForce not working 1 Answer

Player freezes upon attaching a "connected body" to a hinge/distance joint 0 Answers

Relative Joint2d: Is there a way limit force to only X or Y axis? 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