goide Posted August 1, 2015 Share Posted August 1, 2015 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. Video: https://db.tt/f01HXSmj 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? Quote Link to comment Share on other sites More sharing options...
LinkTree Posted August 1, 2015 Share Posted August 1, 2015 If you could rephrase what you are trying to ask better it would make it a lot easier to answer your question. Please do not be offended but at the moment I do not understand what you are saying. What is your goal? Quote Link to comment Share on other sites More sharing options...
goide Posted August 2, 2015 Author Share Posted August 2, 2015 I need to make an object of class animation(game.Animation) rotate and point where my hero. Quote Link to comment Share on other sites More sharing options...
LinkTree Posted August 3, 2015 Share Posted August 3, 2015 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 anglefunction 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;} goide 1 Quote Link to comment Share on other sites More sharing options...
goide Posted August 3, 2015 Author Share Posted August 3, 2015 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); } Quote Link to comment Share on other sites More sharing options...
LinkTree Posted August 3, 2015 Share Posted August 3, 2015 Did you solve it already? if not I think what you are missing is an update function on your Enemigo class that will call the anguloEntre function on every frame and update the sprite's angle. Quote Link to comment Share on other sites More sharing options...
goide Posted August 3, 2015 Author Share Posted August 3, 2015 yes, I resolved, and if that was my mistake, that by the method call in the wrong place. Thanks for everything, for your help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.