Missile
1 post • Page 1 of 1
Missile
Code explanation:
scene.my.mspd4 = -12 * (e.normal(0) * (math.cos(friction + 0.5 * math.pi)) + e.normal(1) * (math.sin(friction + 0.5 * math.pi))) / (((math.cos(friction + 0.5 * math.pi)) ^ 2 + (math.sin(friction + 0.5 * math.pi)) ^ 2) ^ 0.5);
{(texturematrix(4) - texturematrix(6) * textscale) > 0 && (texturematrix(5) - texturematrix(7) * textscale) >= 0} ? {friction = math.atan((texturematrix(5) - texturematrix(7) * textscale) / (texturematrix(4) - texturematrix(6) * textscale))} : {};
{(texturematrix(4) - texturematrix(6) * textscale) > 0 && (texturematrix(5) - texturematrix(7) * textscale) < 0} ? {friction = math.atan((texturematrix(5) - texturematrix(7) * textscale) / (texturematrix(4) - texturematrix(6) * textscale)) + 2 * math.pi} : {};
{(texturematrix(4) - texturematrix(6) * textscale) < 0} ? {friction = math.atan((texturematrix(5) - texturematrix(7) * textscale) / (texturematrix(4) - texturematrix(6) * textscale)) + math.pi} : {};
{(texturematrix(4) - texturematrix(6) * textscale) == 0 && (texturematrix(5) - texturematrix(7) * textscale) > 0} ? {friction = 0.5 * math.pi} : {};
{(texturematrix(4) - texturematrix(6) * textscale) == 0 && (texturematrix(5) - texturematrix(7) * textscale) < 0} ? {friction = 1.5 * math.pi} : {};
{(texturematrix(4) - texturematrix(6) * textscale) == 0 && (texturematrix(5) - texturematrix(7) * textscale) == 0} ? {friction = 0} : {};
{controlleracc == 2} ? {
Scene.addcircle({
zdepth := -inf;
pos := e.pos;
buttonDestroy = "l";
vel := ((e.pos - [texturematrix(0), texturematrix(1)]) / (sim.time - texturematrix(2))) + ([(e.normal(0)), (e.normal(1))] * 10);
radius := 0.09375;
collideset := 32;
drawcake := false;
oncollide := (e)=>{density = 0};
heteroCollide := true;
drawborder := false;
color := [0, 0, 0, 1];
density := density * 13;
friction := 0.0;
restitution := 0
})
} : {};
texturematrix = [e.pos(0), e.pos(1), sim.time, ((texturematrix(0) - e.pos(0)) ^ 2 + (texturematrix(1) - e.pos(1)) ^ 2) ^ 0.5 / (sim.time - texturematrix(2)), (scene.my.pos(0) - e.pos(0)) / ((scene.my.pos(0) - e.pos(0)) ^ 2 + (scene.my.pos(1) - e.pos(1)) ^ 2) ^ 0.5, (scene.my.pos(1) - e.pos(1)) / ((scene.my.pos(0) - e.pos(0)) ^ 2 + (scene.my.pos(1) - e.pos(1)) ^ 2) ^ 0.5, (texturematrix(0) - e.pos(0)) / (sim.time - texturematrix(2)), (texturematrix(1) - e.pos(1)) / (sim.time - texturematrix(2)), ((scene.my.pos(0) - e.pos(0)) ^ 2 + (scene.my.pos(1) - e.pos(1)) ^ 2) ^ 0.5];
{controlleracc > 2} ? {controlleracc = 0} : {controlleracc = controlleracc + 1};
textscale = -0.5 / texturematrix(8);
airfrictionmult = {texturematrix(3) > 100} ? {10000} : {0}
Orange: This section gathers all the values needed to calculate things.
Texturematrix = [pos x, pos y, time, speed, normalized x distance, normalized y distance, velocity x, velocity y, distance]
Blue: This section finds the angle between the velocity*textscale and the position of the Missile relative to scene.my.pos using atan2. Textscale changes how much velocity affects the angle.

Red: This section controls the angle of the rocket with the angle found in the blue section.
Green: This section spawn a circle every 3 frames (reduces memory leak).
Purple: This caps the speed at 100 m/s, it can be changed.
Registered: 2008-10-16


-

Ivanlul - Posts: 763
- Joined: Mon Aug 31, 2009 11:19 pm
- Location: US
1 post • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 3 guests




