• 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

5 Replies

· Add your reply
  • Sort: 
avatar image
3

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 JanZagar · Feb 17, 2019 at 07:15 PM

Hey, thanks my dude/dudet :D

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 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 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Unity2D Joints not rotating the way I want them to. 1 Answer

Hinge Joint 2D 0 Answers

Strange Problem with Torque-based Rotation 0 Answers

how to make non elastic hinge joint in 2d mode 1 Answer

Using Hinge Joint 2D with scaled UGUI 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges