• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Aug 29th, 2019 120 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. shell = instance_create(shell_x,
2.                         shell_y,
3.                         shell_object);
4.
5. with (shell) {
6.
7.     // assign bullet owner to ensure it doesn't hit self
8.     owner = other.owner;
9.
10.     // give bullet its direction
11.     image_angle = other.image_angle;
12.     direction = image_angle;
13.
14.     // for calculating travel distances, get origin and target x, y, z locations
15.     origin_y = y;
16.     origin_x = x;
17.     origin_z = other.z;
18.
19.     target_x = other.desired_point[0];
20.     target_y = other.desired_point[1];
21.     target_z = other.desired_point[2];
22.
23.     // set target distance
24.     target_distance = point_distance(x, y, other.desired_point[0], other.desired_point[1]);
25.
26.     // make sure distance isn't greater than maximum
27.     if (target_distance > other.maximum_range) target_distance = other.maximum_range;
28.
29.     show_debug_message("Target distance: " + string(target_distance));
30.
31.     // shells total velocity in all axises
32.     shell_velocity = other.shell_velocity;
33.
34.     // use for testing purposes, delete when formulas work
35.     target_z = 40;
36.
37.     // convert velocity from pixels per tick to pixels per second
38.     var v = shell_velocity * room_speed; // convert speed per tick to speed per second
39.
40.     // v to the power of 2
41.     var v_2 = power(v, 2);
42.
43.     // v to the power of 4
44.     var v_4 = power(v, 4);
45.
46.     // gravity
47.     var g = 9.8 * 10;
48.
49.     // displacement to target in vertical and horizontal
50.     var dis_h = target_distance;
51.     var dis_z = (target_z - origin_z);
52.     var dis_h_2 = power(dis_h, 2);
53.
54.     // calculate potential angles, one will be high, one will be low
55.     var theta_0 = radtodeg(arctan(  (v_2 - sqrt(v_4 - g * ( g * dis_h_2 + 2 * dis_z * v_2)) ) / (g * dis_h)   ));
56.     var theta_1 = radtodeg(arctan(  (v_2 + sqrt(v_4 - g * ( g * dis_h_2 + 2 * dis_z * v_2)) ) / (g * dis_h)   ));
57.
58.     // set to angle closest to 0
59.     if (abs(theta_1) < abs(theta_0)) theta = theta_1;
60.     else theta = theta_0;
61.
62.     show_debug_message("Theta is: " + string(theta) + " based on a theta_0 of: " + string(theta_0) +
63.         " and theta_1 of: " + string(theta_1));
64.
65.     // horizontal velocity, x and y axis