Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Swinging Object

Discussion in '2D' started by midsideslimshady, Aug 22, 2016.

  1. midsideslimshady

    midsideslimshady

    Joined:
    Jul 19, 2016
    Posts:
    5
    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?
     

    Attached Files:

  2. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    Hinge Joint 2D has Angle Limits you can define. Set your upper and lower limits to like 315 and 225 respectively or whatever looks right to you. The axe will stop when it hits those limits though, so maybe your problem is that you're giving it too much force and it goes around too far.

    Or you can use an Animator with an ease to simulate the swinging so it can go on indefinitely.

    https://docs.unity3d.com/Manual/class-HingeJoint2D.html
     
    theANMATOR2b likes this.
  3. midsideslimshady

    midsideslimshady

    Joined:
    Jul 19, 2016
    Posts:
    5
    You are right, i give it too much force so that my axe goes around too far. The thing is I adjust those values many times but it just goes in one direction(the left or the right depends on the value of the motor speed is positive or negative). I want it to goes to the left and to the right and back to the left ... Can you please give me the specific values(motor speed, maximum motor force and the lower and upper angle)?
     
  4. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    As far as I know the Motor will give you a single direction of rotation, constantly.

    Does this swinging axe go on forever like an obstacle? Because you may want to use an Animator for that, and animate the rotation with an ease so you can loop it forever. Otherwise the axe will eventually slow down and stop due to gravity and drag unless you program it to add forces at the peaks of the swing.