Jump to content

Rotation Animation


goide
 Share

Recommended Posts

A question.

 

I need to rotate an animation, in the direction of another object.

 

Create a method that allows me to do this. but for a sprite, but when I try to type an object animation, but does not rotate.

 

watch the video, which have two methods, which are angles to me to turn my animation, you work to perfection and the other not.

 


 


Look how the sprite with the same angle, pointing to my hero.

 

and when I use the animation with the same angle and not pointing to it.

 

and when I change the method by spinning according to the pointer, rotating smoothly.

 

 


the animation changes its angle to the method I use for the angle of the pointer, but the method if it works, to change the angle for the sprite. but to change the angle of the animation is not working.

 

why?

Link to comment
Share on other sites

I need to make an object of class animation(game.Animation) rotate and point where my hero.

you need to get the x,y position of both your hero and enemy and use a function like this to calculate the angle between them and then rotate the enemy by this angle

function angle(cx, cy, ex, ey) {  var dy = ey - cy;  var dx = ex - cx;  var theta = Math.atan2(dy, dx); // range (-PI, PI]  theta *= 180 / Math.PI; // rads to degs, range (-180, 180]  //if (theta < 0) theta = 360 + theta; // range [0, 360)  return theta;}
Link to comment
Share on other sites

Thank you very much for your answer, but look and achieve my goal.

 

look this is my function, is the angle of my two objects, and my mistake was that it was not updated each positioned himself as the animation was moving.

 



anguloEntre: function(source, target){
var dx = target.x - source.x;
var dy = target.y - source.y;

return Math.atan2(dy, dx);
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...