Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Hareesun

I don't suppose anyone's worked out a way to do this yet?

I'm attempting a simple driving mechanic, but can't quite figure it out.

Any help is greatly appreciated :)

1 decade ago by nefD

I've been doing a lot of rotating in my current project, and it's actually quite simple. The Animation object has an angle property (note: takes radians, not degrees), which you can use to set the rotation of one of an entities anim's. You can find it here: http://impactjs.com/documentation/class-reference/animation

One function you might also find useful in conjunction with this is the Entity classes angleTo method, which gives you the angle (in radians) from that entity to another entity. Very useful. If you want to find the angle (in radians) to an arbitrary point, like the mouse cursor, you can do something like this in the update method:

var mx = ig.input.mouse.x + ig.game.screen.x;
var my = ig.input.mouse.y + ig.game.screen.y;
var mouseAngle =  Math.atan2(
    my - (this.pos.y + this.size.y/2),
    mx - (this.pos.x + this.size.x/2)
);
this.anims.idle.angle = mouseAngle;

1 decade ago by Hareesun

Thanks for the tip, nefD :)

1 decade ago by TigerJ

Just wanted to say thank you for posting this! I was able to find my error when calculating an angle of fire for my game.
Page 1 of 1
« first « previous next › last »