Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- shell = instance_create(shell_x,
- shell_y,
- shell_object);
- with (shell) {
- // assign bullet owner to ensure it doesn't hit self
- owner = other.owner;
- // give bullet its direction
- image_angle = other.image_angle;
- direction = image_angle;
- // for calculating travel distances, get origin and target x, y, z locations
- origin_y = y;
- origin_x = x;
- origin_z = other.z;
- target_x = other.desired_point[0];
- target_y = other.desired_point[1];
- target_z = other.desired_point[2];
- // set target distance
- target_distance = point_distance(x, y, other.desired_point[0], other.desired_point[1]);
- // make sure distance isn't greater than maximum
- if (target_distance > other.maximum_range) target_distance = other.maximum_range;
- show_debug_message("Target distance: " + string(target_distance));
- // shells total velocity in all axises
- shell_velocity = other.shell_velocity;
- // use for testing purposes, delete when formulas work
- target_z = 40;
- // convert velocity from pixels per tick to pixels per second
- var v = shell_velocity * room_speed; // convert speed per tick to speed per second
- // v to the power of 2
- var v_2 = power(v, 2);
- // v to the power of 4
- var v_4 = power(v, 4);
- // gravity
- var g = 9.8 * 10;
- // displacement to target in vertical and horizontal
- var dis_h = target_distance;
- var dis_z = (target_z - origin_z);
- var dis_h_2 = power(dis_h, 2);
- // calculate potential angles, one will be high, one will be low
- var theta_0 = radtodeg(arctan( (v_2 - sqrt(v_4 - g * ( g * dis_h_2 + 2 * dis_z * v_2)) ) / (g * dis_h) ));
- var theta_1 = radtodeg(arctan( (v_2 + sqrt(v_4 - g * ( g * dis_h_2 + 2 * dis_z * v_2)) ) / (g * dis_h) ));
- // set to angle closest to 0
- if (abs(theta_1) < abs(theta_0)) theta = theta_1;
- else theta = theta_0;
- show_debug_message("Theta is: " + string(theta) + " based on a theta_0 of: " + string(theta_0) +
- " and theta_1 of: " + string(theta_1));
- // horizontal velocity, x and y axis
- velocity_h = shell_velocity * radtodeg(cos(degtorad(theta)));
- // vertical velocity, z axis
- velocity_v = shell_velocity * radtodeg(sin(degtorad(theta)));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement