How do I rotate a sprite toward another but not from origin?

0 favourites
  • 11 posts
From the Asset Store
2D fighting template based in the game that defined the fighting games genre.
  • [attachment=0:9sdpyvza][/attachment:9sdpyvza]

    Hello guys. That's a screenshot from my editor.

    The arm is a different sprite from the body. The origin of the arm is on the blue circle.

    The player can rotate that red ball around the player. I want the arm to point at the red ball always, but since the arm is pinned to the body, it rotates funny. The hand doesn't exactly point to the red ball.

    How can I both lock the arm to the body at the shoulder level AND make it rotate in a way the hand follows the red ball?

  • I am guessing your arm is in the wrong orientation in the editor. If you edit your arm sprite it should look like the shoulder is at the left and the hand at the right. The place the image point at the shoulder. Its should work just fine then.

  • Thanks for the help spongehammer.

    It really doesn't matter what way I set in on the editor, when I play the game it will always start in a specific position.

    I don't really know what the problem is, could you or anybody take a look at my project?

    You can move the red circle with buttons Q and E or the left stick if you have a gamepad ... mancy.capx

  • Your arm sprite needs to be horitontal in the editior. If you rotate it 90 degrees so the hand is on the right It will work. In actual fact the arm image needs editing externaly so its horizontal not at an angle. Also you need to alter your aim calculations. I am not sure from what i see exactly where the red aim point is supposed to be.

    It seems a little overcomplicated for what you are trying to achieve.

  • See attached capx. Either drag the girl around or the red ball.

  • Didn't seem to make much progress by editing the image and rotate it as you suggested.

    I'm not sure what's the problem with the aim calculations. Could you elaborate on this? It's supposed to move 180 degrees around the player, like a semicircle

  • Here is another option. Use the Q & E keys to move the aim.

  • The pointing there works as expected Unfortunately in my game you move the character around the planet (A and D), and you don't want him to be able to move the aim towards his own planet, that's why full rotation is limited.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Well limiting rotation using my method is simply a check to see if it is between angles. That way you can set it to rotate to and from any angle.

  • Ok! I implemented your way in my prototype and at least I got the "pointing" working properly now. Thank you very much

    Still having problems limiting the angle in away the Aim doesn't touch the planet, because here:


    The angle is not the same that when she is down here:


    This needs some math creativity. How can I clamp the rotation of the red circle so no matter the position the player is around the planet, the circle never can rotate over the planet?

  • Why not just make the red circle a bit larger and detect when it overlaps the planet. If it does stop the rotation.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)