Target Match
#710 posted by JPL on 2012/03/17 20:18:54
I guess the main problem is not to obtain the parabolic curve, that can be even coded very simply like an exponential code (i.e x = x/2 or x = 2x). no I guess the challenge is rather to be able to obtain the projectile to perform direct hit to the player (if not moving). in order to achieve this, a reverse calculation is required: you know player position, monster position, projectile weight, hence it is possible to determine velocity and angle to apply... that could be very interesting as more realistic ;)
#711 posted by necros on 2012/03/17 20:27:21
did this a while ago.. it was supposed to be for a leaping monsters and would trace the parabolic course in increments via a while look and tracelines so check if the leap parabola was clear...
traceFraction = 0;
while(traceProjection <= 1)
{
traceProjection = traceFraction + 0.25; //project the trace. will make for 4 traces.
local vector trace_pos0, trace_pos1;
trace_pos0 = self.origin + ( (dir * (hdist * traceFraction)) + ( '0 0 1' * ( ((vtime * 400)*(vtime * traceFraction)) + (0.5 * (vtime * traceFraction) * (vtime * traceFraction) * -800) )));
trace_pos1 = self.origin + ( (dir * (hdist * traceProjection)) + ( '0 0 1' * ( ((vtime * 400)*(vtime * traceProjection)) + (0.5 * (vtime * traceProjection) * (vtime * traceProjection) * -800) )));
traceline(trace_pos0, trace_pos1, 0, self);
bprint (vtos(trace_endpos));
bprint (" -> ");
if (trace_fraction < 1)
traceProjection = 1000000; //cause a break
traceFraction = traceProjection;
}
dunno if that code is 100% correct... or even helpful. :P
Necros
#712 posted by JPL on 2012/03/18 08:47:14
I guess what is interesting is not that much the result, but the logical reasoning you made to obtain it ;)
#713 posted by necros on 2012/03/18 17:56:41
oh sorry yeah, should have explained it a bit. :P
you'll notice there's two vars, traceFraction and traceProjection.
these should be only values of 0 to 1.
next is trace_pos0 and trace_pos1.
we determine these points by using that physics formula that describes position relative to time with an initial velocity and taking into account gravity. (i subbed 400 in to any 'g' variables, which, sorry to say preach, i figured out totally by guessing... ^_^;)
this is where traceFraction and traceProjection come in. if you look at the first line of the loop, traceProjection is always 25% ahead of traceFraction.
trace_pos0, then, is the origin of the traceline and trace_pos1 is 25% ahead through the trajectory.
incidentally, you could increase the 'resolution' of the trace by decreasing 0.25 to 0.1 or something to get 10 iterations instead of 4.
if you can imagine a typical parabolic trajectory, what you're doing in that code is tracing a line, first, from the starting point to 25% into that trajectory.
then, from there, tracing another 25% forward to the middle of the trajectory, etc etc.
if at any point the traceline fails (trace_fraction < 1, ie: something blocked the trace)
then we break out of the loop and notify the rest of the code what happened.
basically, i turned quake into a really crappy 3d graphing calculator. :P
#714 posted by necros on 2012/03/18 18:05:00
oops, there was additional information i forgot about (i wrote this years ago so i forgot how it works! :D)
this is the start of the code (before that loop):
epos = self.enemy.origin;
//epos = self.enemy.origin + dir;
zsep = epos_z - self.origin_z;
dist = vlen(epos - self.origin);
dir = epos - self.origin;
dir_z = 0;
dir = normalize(dir);
if (zsep > 64) //player is too high, forget it.
return;
temp1 = epos;
temp1_z = 0;
temp2 = self.origin;
temp2_z = 0;
hdist = vlen(temp2 - temp1);
if (hdist > 768) //player is too far, stop
return;
if (hdist < 440)
{
hspeed = hdist; //do a 1 second jump.
vtime = 1;
}
else
{
hspeed = 440; //max out at 440 horizontal speed and jump higher to compensate.
vtime = hdist / hspeed;
}
i guess the important things is noting that dir is a flattened normalized vector towards the target and that vtime is the amount of time we want to spend in the air.
Necros
#715 posted by JPL on 2012/03/18 21:06:32
Oh, I see, you made it like a move forward, rotate, move forward, rotate, etc... like polar coordinates or (better) vectorized move: interesting, I was not thinking it was possible doing it this way actually ;)
And thanks for the explanations :)
PHP Is Kicking My Ass At The Moment
#716 posted by RickyT33 on 2012/03/23 18:08:51
The sooner I can get my assignment finished, the sooner I can get back to mapping :)
This bloody search_array thing is kicking my ass. Trying to use php to search an array of info. Its a multi-dimensional array. I swear I have looked all over for a solution and have had no luck.
http://www.php-forum.com/phpforum/viewtopic.php?f=2&t=17353
No Php Guru
#717 posted by bear on 2012/03/23 18:26:19
But the search_array func probably isn't built for multi dimensional arrays. Seems to be versions of that in the comments of the search array in the php docs:
http://php.net/manual/en/function.array-search.php
Yeah I've Been Sifting Through That
#718 posted by RickyT33 on 2012/03/23 19:25:54
I dunno, it seems I'm just not getting something.
I think it's to do with the way I have my array. Which is awkward because It's just the way it comes from the XML file. Blerg.
Oh God...
#719 posted by jt_ on 2012/03/23 21:13:11
Xml...*shudders*
Yeah I Know
#720 posted by RickyT33 on 2012/03/24 08:07:10
Any sensible person would design a DB in MySQL, but we are not allowed to use MySQL (go figure?!) - which sucks because any real-world application would use MySQL or SQL or even .net + access or whatever, but 'noooooo', not my retarded course. php + XML is the recipe of the day. Fuck it, I guess I'll learn something at the end of the day ...
Dude
ditch array_search and iterate through the arrays manually. It's pretty simple.
Could You Perhaps Show Me An Example Of A Loop?
#722 posted by RickyT33 on 2012/03/24 08:35:24
I can handle a stupified approach, I just wanna get a fucking A. I don't care if I have to re-design my data structure completely, I have been thinking about this for far to long now and my brain hurts...
#723 posted by Spirit on 2012/03/24 09:41:02
Hey, XML can be fun and it is quite simple if you use a good parser. seriously!
#724 posted by JneeraZ on 2012/03/24 10:53:16
I enjoy the transition from, "Stupid class, can't use a database, have to use XML, *grumble*" to "can you show me an example of a loop?"
Walk before you run, Ricky. :)
Ricky
If you don't know what a loop looks like, how can you expect to get an A in a programming class?
Here is an explanation of the most important loop constructs in PHP:
http://nefariousdesigns.co.uk/loopy.html
Lol - I Do Know What A Control Loop Looks Like
#726 posted by RickyT33 on 2012/03/24 20:33:18
However that is a rather good reference!
Thanks :)
I don't really know that many types of loop, just while loops and for loops.
I think I'm getting somewhere with it now, I used the following bit of code to remove the extra level of array which was preventing me from being able to use the array_search function:
$b=$a['Rrestaurant'];
Dumb, huh? I thought I was going crazy!
Also - I WILL get an 'A'. I could have done the lame thing and just planned a static website. The level of the course is not so high that I have to do a PHP website, but I really want to learn some programming, so I set myself the challenge.
August last year, I had never coded anything really, since messing around with BASIC like 15 years ago.
Now I have coded a text-based version of minesweeper (which is 200KB, fuck)(the second half of the assignment will be probably a discussion of how I can use functions to simplify my code).
And this flippin XML/PHP project. You've got to start somewhere!
But seriously, thanks again.
Success!
#727 posted by RickyT33 on 2012/03/24 21:51:54
OK, so now that I've figured out how to access my arrays within the array that was within an array, and started iterating through it manually with my loops, I'm having success :)
$search = 'the';
$resultsCounter = 0;
function object2array($object){return@json_decode(@json_encode($object),1);}
$xml = simplexml_load_file("places.xml");
$a = object2array($xml);
$b=$a['Rrestaurant'];
$count = count($b);
for ($x=0;$x<=($count-1);$x++){
$c = $b[$x];
$d = $c['Rinfo'];
if (strpos($d,$search)) { echo $c['Rname'] . '<br /><br />' . $c['Rinfo'] . '<br /><br />' . $c['Rindex'] . '<br /><br />'; $results[$resultsCounter] = $c['Rindex']; $resultsCounter++; }
}
$count = count($results);
for ($x=0;$x<=($count-1);$x++){
echo $results[$x] . ' ';
}
I'm sure that's probably pretty hideous, but its giving me nice search results :) :) :)
Doh!
#728 posted by RickyT33 on 2012/03/24 21:53:13
$search = 'the';
$resultsCounter = 0;
function object2array($object) {return@json_decode(@json_encode ($object),1);}
$xml = simplexml_load_file ("places.xml");
$a = object2array($xml);
$b=$a['Rrestaurant'];
$count = count($b);
for ($x=0;$x<=($count-1);$x++){
$c = $b[$x];
$d = $c['Rinfo'];
if (strpos($d,$search)) { echo $c['Rname'] . '<br /><br />' . $c['Rinfo'] . '<br /><br />' . $c['Rindex'] . '<br /><br />'; $results[$resultsCounter] = $c['Rindex']; $resultsCounter++; }
}
$count = count($results);
for ($x=0;$x<=($count-1);$x++){
echo $results[$x] . ' ';
}
Now Try:
#729 posted by bear on 2012/03/24 23:57:30
some better variable names and have a look at foreach
Yeah
Don't call variables 'a' or 'b' - give them a name that reflects their meaning in the program.
Ah - Good Idea.
#731 posted by RickyT33 on 2012/03/25 00:21:37
$wholeArray
$wholeCumbrianRD
$wholeRrestaurant
$wholeKey
Craving Your Indulgences Again
#732 posted by Mike Woodham on 2012/03/25 16:32:25
I don't do much qc but whenever I do I find myself running into brick (BRICKL_0 or similar) walls.
I have a procedure that I want to run x times as selected from the editor (self.something = x). I want to say along the lines of:-
void () Proc1
do some stuff
while (self.something >0)
do this
wait random y to z seconds
self.something = selfsomething - 1
ewhile
do some other stuff
endproc
(I know I am mixing languages, I am just trying make it look obvious what I am doing)
When looking at 'think' and 'nextthink' examples, they all seem to act on an external procedure/function before returning to the calling procedure/function. I also see use of recursion i.e. a procedure/function calling itself.
Is it necessary to use 'think' and 'nextthink' for timing purposes in my ditty above or is there some other construct available. If I need to use 'think' and 'nextthink' is it therefore advisable to separate the 'while/ewhile' (or whatever loop is used) into its own proc/func?
#733 posted by necros on 2012/03/25 16:43:40
you are thinking about it the wrong way.
best to think about what gets done in a frame and what doesn't.
nextthink and think is what you need to delay over multiple frames.
doing a while loop will do everything in the same frame.
in this case, you don't want a while loop at all.
void() proc1
{
//some stuff here
self.think = proc1; //run this again
self.nextthink = time + (some random amount here);
}
the way nextthink works sort of is that the engine looks at what nextthinks are > current time and when they become < current time, the engine sets nextthink the 0 and runs the .think function with self as the 'thinking' entity.
Necros
#734 posted by Mike Woodham on 2012/03/25 16:58:26
So the engine is not waiting for my procedure but it will have my 'thinks' queued up? Also, do I not think of this a true recursion?
By the way, I just ovelayed the draflam2.spr with the bigexp.spr (just via an entity choice in the editor and using two entities) and it looks pretty smart. I am not sure what it will look like to a player seeing it for the first time in a game - you know how fussy Quake people are :) But it looks good enough to blow the head of a Vermis!
|