1 (edited by CarmineZ 2010-12-05 23:02:46)

Topic: laser hit, not well-coded

// TODO: should be more general
CHARACTER *GAMEWORLD::intersect_character(vec2 pos0, vec2 pos1, float radius, vec2& new_pos, ENTITY *notthis)
{
    // Find other players
    float closest_len = distance(pos0, pos1) * 100.0f;
    vec2 line_dir = normalize(pos1-pos0);
    CHARACTER *closest = 0;

    CHARACTER *p = (CHARACTER *)game.world.find_first(NETOBJTYPE_CHARACTER);
    for(; p; p = (CHARACTER *)p->typenext())
     {
        if(p == notthis)
            continue;
            
        vec2 intersect_pos = closest_point_on_line(pos0, pos1, p->pos);
        float len = distance(p->pos, intersect_pos);
        if(len < CHARACTER::phys_size+radius)
        {
            if(len < closest_len)
            {
                new_pos = intersect_pos;
                closest_len = len;
                closest = p;
            }
        }
    }
    
    return closest;
}

because there may be a Tee with a shorter "closest_len" behind another Tee that stands between him and the laser
see my drawing for explain

http://www.continua.altervista.org/laser.png

i tried in game to jump and shoot to create the same situation and you can see result by screenshoot
http://www.continua.altervista.org/screenshoot.png

2

Re: laser hit, not well-coded

one of possible solution is to substitute whit this:
           
if(distance(pos0, p->pos) < closest_len)
            {
                new_pos = intersect_pos;
                closest_len = distance(pos0, p->pos);
                closest = p;
            }

3

Re: laser hit, not well-coded

I rammed my head onto the wall to get your point but its good that you reported this, i hope a couple of dev's would look at this. But they wont fix this because they are busy atm.

"The scientists of today think deeply instead of clearly. One must be sane to think clearly, but one can think deeply and be quite insane." Nikola Tesla.

4

Re: laser hit, not well-coded

Good idea to post this issue on the board, noticed that some time ago reading the code, but I thought it was a will from the developpers. They maybe wanted to avoid people to become "teeish shields" for flaggers, but as the 'bug' - if it is one - isn't appearing often in vanilla, I guess they simply did not notice it.
You should open an issue on github.

Not Luck, Just Magic.

5

Re: laser hit, not well-coded

I posted this just a strange situation to determine if an error or a choice of developers. I realized that this exception because I'm making a mod and I was interested in the correct intersection point, because now "intersect_pos" is just the closest point to the line and not the real point of collision. now the point is always inside the tee, for my mod i need to move it on the circumference of the tee