Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Catapult charging effect

Discussion in '2D' started by YanivAvrahami, Aug 29, 2016.

  1. YanivAvrahami

    YanivAvrahami

    Joined:
    Jun 26, 2016
    Posts:
    51
    I made a catapult object that is made of another 2 objects (head and body). The body is connected to world space with hinge joint, and I limited the angles. The head is just connected to the body with another hinge joint with limits too.

    Now I try to make that whenever the player is holding the Spacebar then the catapult start to charge, im doing it by changing the body limit lower angle over time but for some reason it does not charge so smoothly as I want it too, hope someone can see the problem.

    arm movement.gif

    And my code is here:

    public class Charge : MonoBehaviour {

    private HingeJoint2D hinge;
    private JointAngleLimits2D hingeLimits;

    void Start() {
    hinge = GetComponent<HingeJoint2D>();
    hingeLimits = hinge.limits;
    }

    void Update () {

    if (Input.GetKey(KeyCode.Space)) {
    hingeLimits.min -= 5f * Time.fixedDeltaTime;
    hinge.limits = hingeLimits;
    }

    }

    }



    Thank you in advance.
     
  2. jamius19

    jamius19

    Joined:
    Mar 30, 2015
    Posts:
    96
    Correct me if I donot understand you correctly, but those catapult actually looks okay!

    What effect are you trying to achieve?
    Be more specific than,
    And use code tags properly!
    It help a lot for us to see whats going on! ;)
     
  3. Hyblademin

    Hyblademin

    Joined:
    Oct 14, 2013
    Posts:
    725
    An explanation of code tags is here, by the way.

    Judging by the cursor moving across the image toward the end of the loop, you captured it at a really low framerate. We can't tell whether an animation is smooth or not if the capture isn't smooth.

    Either that, or your project is actually running at a low framerate. If that's the case, then that's your entire problem.

    Which of these is happening?
     
  4. YanivAvrahami

    YanivAvrahami

    Joined:
    Jun 26, 2016
    Posts:
    51
    It is 60 fps capture, so what you see is what I see in the actual editor. And how can I check the fps my game runs on?
     
  5. Hyblademin

    Hyblademin

    Joined:
    Oct 14, 2013
    Posts:
    725
    Open the profiler view and push record. Play your scene, and see what exactly is taking up all your resources. You'll also get an estimate of the frame rate from the graph view.