Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / How do I make an enemy target a moving player and fire?
- - By Acturus Date 2019-08-10 15:35
I can make an enemy chase the player and move around but in terms of changing the enemies angle in the direction of a players location at a given time I'm clueless. So how do you get a player to turn its angle to the center of a player's location?

Thank You,

Jordan
Parent - By nifriz Date 2019-08-12 07:52
Hi,
you must calculate the angle.

tan^−1 delta_y/delta_x=θ

Where θ is yor angle, delta_y and delta_x are coordinate difference between your character (player and enemie).

Calculated the angle you can draw image rotated, using draw_rot method instead of draw.

Maybe this mine little Ruby test can helps you , how to use draw_rot
Parent - - By jlnr (dev) Date 2019-08-19 21:21
You can find the angle from point 1 to point 2 using Gosu::angle(x1, y1, x2, y2), which internally does the tan^-1 that nifriz mentioned.
Parent - By Acturus Date 2019-08-22 21:19
Thank you!
Up Topic Gosu / Gosu Exchange / How do I make an enemy target a moving player and fire?

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill