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
1
Question by midsideslimshady · Aug 23, 2016 at 07:41 AM · hingejoint2d

Swinging Object

Hi, I got an axe and i want to make it swing with the fixed point is the red circle in the pic. I've tried using the hinge joint 2D but it just rotates circularly (my aim is to swing between 2 angles), maybe i don't know how to adjust the value properly. Can anyone give me some workarounds? alt text

adasd.png (166.1 kB)
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 5c4r3cr0w · Aug 23, 2016 at 07:56 AM 0
Share

Try it using transform component like :

 public float angleRange;
 
 void Update ()
     {
 
         transform.eulerAngles = new Vector3 (0, 0, $$anonymous$$athf.PingPong (Time.time * 10f, angleRange) - angleRange / 2);
 
     }
avatar image midsideslimshady · Aug 23, 2016 at 10:27 AM 0
Share

@5c4r3cr0w my aim is the axe rotates around a fixed point it's the red point in the pic. Your code doesn't make the axe rotate around a fixed point, it's just a normal rotation

avatar image 5c4r3cr0w midsideslimshady · Aug 24, 2016 at 07:12 AM 0
Share

You need to create an empty object an by parenting it properly to your axe it'll work as you desire

avatar image Rajeesh_AR · Aug 23, 2016 at 10:39 AM 3
Share

You could rotate AXE from red point also with the code provided by @5c4r3cr0w (if currently its rotating at center) .. For that, Add your AXE game object into another gameobject such that, the pivot of the new gameObject (parent) comes at the red point of the AXE gameobject. Then rotate the new gameObject

4 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by TheDoubleG · May 26, 2017 at 04:17 PM

@midsideslimshady , i know this is an old post and all but I kinda ran into a similar problem`using a 3d project but this is how I worked around it

UnityEngine;

public class Penduling : MonoBehaviour {

 public float delta = 1.5f;  // Amount to move left and right from the start point
 public float speed = 2.0f;
 public float direction = 1;

 private Quaternion startPos;

 void Start()
 {
     startPos = transform.rotation;
 }

 void Update()
 {
     Quaternion a = startPos;
     a.x += direction * (delta * Mathf.Sin(Time.time * speed));
     transform.rotation = a;
 }

} `

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
avatar image
0

Answer by Develoop · Nov 06, 2020 at 11:34 PM

The algorithm works really well, great work JanZagar. Thank you! :) P.S. I have problems with hinge joint too, it's not worked like I want...

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
avatar image
0

Answer by idbrii · Feb 23, 2021 at 05:10 PM

HingeJoint2D has angle limits. You can use those to prevent 360 rotation.

You could check jointAngle in Update() for when it reaches the limit and then AddTorque or change the direction of the motor.

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
avatar image
0

Answer by flare38888 · Feb 23, 2021 at 06:24 PM

You could animate it and enable the hinge joint when it hits something, giving it the illusion of swinging.

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

9 People are following this question.

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

Related Questions

Set value of HingeJoint2D.jointAngle? 0 Answers

How to enforce HingeJoint2D angle limits? 0 Answers

Why does the Unity HingeJoint2D not work when enabled during play? 0 Answers

Connect hingejoint with collision object 0 Answers

Chain in 2D top down perspective. 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