Author Topic: Mass raycast problems (270c)  (Read 865 times)

0 Members and 1 Guest are viewing this topic.

Offline dnmr

  • Camper
  • ***
  • Posts: 315
  • emotionally handicapped
Mass raycast problems (270c)
« on: January 17, 2010, 05:11:10 am »
This code is supposed to move the player to the furthest empty spot within the specified range in his movement direction. If you've played hexer you should be pretty familiar with this. There's a problem with this on the new scriptcore though. Sometimes it messes up and returns FALSE for raycasts on open space.

After every raycast, the distance between the points is written to the console (normally 50 in this example), as well as the dist variable that "holds the distance from Point1 to Point2". And that dist turns out to be 9999999 (wtf?)

Any ideas? I dont think it was like this in previous versions...

Code: (pascal) [Select]
const
  aetherstep = 50;
  range = 447;



function OnCommand(ID: Byte; Text: string): boolean;
var i,j: integer;
    dist,X,Y,PosX,PosY,VelX,VelY: single;
begin
  result := false;
 
  PosX := GetPlayerStat(id,'X');
  PosY := GetPlayerStat(id,'Y');
  VelX := GetPlayerStat(id,'VelX');
  VelY := GetPlayerStat(id,'VelY');
  If (VelX <> 0) or (VelY <> 0) then begin
    dist := sqrt(VelX*VelX + VelY*VelY);
    X := VelX/dist; // x direction of movement
    Y := VelY/dist; // y direction of movement
    PosX := GetPlayerStat(id,'X') + range * X;
    PosY := GetPlayerStat(id,'Y') + range * Y;
    VelX := X * aetherstep; // x step (back from destination)
    VelY := Y * aetherstep; // y step (back from destination)
    j := range div aetherstep;
   
    WorldImage(0,10,28,PosX,PosY,1.0);
   
    for i := 1 to j do begin
//            sleep(10);
     
      WorldImage(0,i,28,PosX,PosY,1.0);
     
      writeln('distance: ' + inttostr(round(distance(PosX,PosY,PosX-velx,PosY-vely))));
      If RayCast(PosX,PosY,PosX-velx,PosY-vely,dist,aetherstep) then begin // yes, we can move here
        MovePlayer(id,PosX,PosY);
        exit;
      end else // raycast if
        writeln(inttostr(i) + ' ' + inttostr(round(dist)));

      posx := PosX-velx; // step back from destination towards the player
      posy := Posy-vely;
    end; // for
    WriteConsole(id,'There''s too much in the way.',$FF0000);
  end else
    WriteConsole(id,'You need to be moving into a direction to Aetherwalk.',$FF0000);

end;







"normal" output
Code: [Select]
/def (127.0.0.1 [dnmr])
distance: 50
1 23
distance: 50
(found free space after two raycasts and moved)



bugged
Code: [Select]
/def (127.0.0.1 [dnmr])
distance: 50
1 9999999
distance: 50
2 9999999
distance: 50
3 9999999
distance: 50
4 9999999
distance: 50
5 9999999
distance: 50
(got false results for 5 iterations and then finally figured it was safe to move)
« Last Edit: January 17, 2010, 05:31:41 am by dnmr »