fixed an allusive bug with a very annoying error message
I had some code where I take the square root ((my speed.x- bullet speed.x)squared + (my speed.y-bullet speed.y)squared). I started getting the ridiculous error message that I can't take the square root of a negative number. Unless the speed of my objects is an imaginary number. It should not be possible for my (speed.x-bullet speed.x) squared to be negative. So it took me a while to find out what was wrong. Finally I found out where the problem was.
physics_apply_force(x, y, N2*3000 *chasenem2.phy_speed_y/chasenem2.phy_speed, N*3000 *chasenem2.phy_speed_x/chasenem2.phy_speed);
For some reason Gamemaker Studio hated is when I divided by chasenem2.phy_speed. I I was applying the y componant of chasenem2 in the x direction and the x component in the y direction to get my ship to dodge the projectile refered to as chasenem2. But I did not what the speed I dodge to be dependent on the speed of the projectile. So I divided by chasenem2.phy_speed to that I dodge at the same speed no matter how fast the projectile moves. But then I started getting ridiculous error messages in other places in my code. Now my code is the following and the strange error messages no longer appear and the game has been running overnight and most of today without crashing. I am annoyed at Gamemaker Studio right now but the problem seems to be fixed.
var impulse8 = 100000;
var sumspeed = phy_speed + chasenem2.phy_speed;
var savedistance = distance_to_object(chasenem2);
var speedcloser = sqrt(sqr(phy_speed_x - chasenem2.phy_speed_x) + sqr(phy_speed_y - chasenem2.phy_speed_y));
var speedcompare = (phy_speed + chasenem2.phy_speed);
var try = speedcloser/speedcompare;
var dirbullet = point_direction(x,y, chasenem2.phy_linear_velocity_x, chasenem2.phy_linear_velocity_y);
var lxdb = lengthdir_x(impulse8, dirbullet);
var lydb = lengthdir_y(impulse8, dirbullet);
if (point_distance(x,y, chasenem2.x,chasenem2.y) < 1300)
{
var distance = sqrt(sqr(x-chasenem2.x) + sqr(y-chasenem2.y))
var prevdist = sqrt(sqr(phy_position_xprevious - chasenem2.phy_position_xprevious) + sqr(phy_position_yprevious- chasenem2.phy_position_yprevious))
{
if (distance < prevdist)
{
physics_apply_force(x,y, N2 * lydb, N * lxdb);
}
Files
Get Treacherous Space
Treacherous Space
Space shooter. Fight in large battles to accomplish missions in this action retro fantasy.
More posts
- Meteors now deal damage to your enemies or alliesJun 27, 2019
- Most of my ships are good at dodging meteors nowJun 21, 2019
- Changed the sprites for most Human shipsJun 19, 2019
- Bug fix, Small AI adjustments and made some levels easierMay 23, 2019
- Added zoom function and made GUI look better. Some AI adjustmentsApr 30, 2019
- You can now select levels with arrow keys as well as the mouseApr 13, 2019
- I have lowered the screen shake for explosionsApr 08, 2019
- I am thinking of lowering the screen shakeApr 07, 2019
Leave a comment
Log in with itch.io to leave a comment.