Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Onwaal (https://forums.graalonline.com/forums/showthread.php?t=74188)

cbk1994 05-25-2007 12:47 AM

Onwaal
 
Can someone PLEASE help me with the onwall checks for a car? :C

I SUCK at onwall checks, I'm just doing

PHP Code:

function willCrash()
{
  
temp.movex getMoveX();
  
temp.movey getMoveY();
  
  if ( 
onwall2temp.movextemp.movey2) )
  {
    return 
true;
  }


can someone please help me with this?

I'm showing an image for the car, which simply rotates.

JkWhoSaysNi 05-25-2007 01:03 AM

The difficult part is detecting where it hits the car and calculating how the car should react (e.g. bounce off or come to a complete stop or just slow down but continue moving or whatever) depending on the angle it hits and the speed it's travelling.

Unless the car is small, using the X/Y co-ordinates will not work because probably that part of the car is not on the wall.

You need to detect ahead of the direction the car is moving and for the width of the car, or do multiple checks.

DustyPorViva 05-25-2007 01:12 AM

Depends, is your car only moving in four directions or is it capable of turning in a complete circle?

JkWhoSaysNi 05-25-2007 01:26 AM

Actually I have some code similar to what you're doing.

This was for an NPC:

PHP Code:

s1 = (onwall2(x+vecx(this.dir)+vecx(this.dir)-abs(vecy(this.dir)),y+vecy(this.dir)+vecy(this.dir)-abs(vecx(this.dir)),1,1)) ? 10;
  
s2 = (onwall2(x+vecx(this.dir)+vecx(this.dir)+abs(vecy(this.dir)*2),y+vecy(this.dir)+vecy(this.dir)+abs(vecx(this.dir)*2),1,1)) ? 10

It puts 2 'sensors' in at the front of the NPC, then I had the NPC decide which way to turn based on the check.

It was actually a line follower which I tried (without success :P ) to develop into a maze solver.

The line follower code may actually help as a base for deciding what should happen depending on which 'sensor' has been hit.

PHP Code:

//Line follower

function onTimeout() {
 
weights = {{1,0,-1},{1,-1,0}};
 
output = {1,1};

  
s1 = (onwall2(x+vecx(this.dir)+vecx(this.dir)-abs(vecy(this.dir)),y+vecy(this.dir)+vecy(this.dir)-abs(vecx(this.dir)),1,1)) ? 10;
  
s2 = (onwall2(x+vecx(this.dir)+vecx(this.dir)+abs(vecy(this.dir)*2),y+vecy(this.dir)+vecy(this.dir)+abs(vecx(this.dir)*2),1,1)) ? 10;
  
res1=weights[0][1]*s1+weights[0][2]*s2+weights[0][0];
  
output[0] = (res1>0) ? 0;
  
res2=weights[1][1]*s1+weights[1][2]*s2+weights[1][0];
  
output[1] = (res2>0) ? 0;



   if ((
output[0]==1)&&(output[1]==1))
    
lturn(); //turn -45 degrees
   
if ((output[0]==0)&&(output[1]==0))
    
rturn(); //turn 45 degrees

   
if ((output[0]==1)&&(output[1]==0))
    
forward(); 
   if ((
output[0]==0)&&(output[1]==1))
    
back();


     
setTimer(0.05);



It actually uses a 2 neuron model (not really a neural net because it's just a 2 neuron model but it could be developed into one)

DustyPorViva 05-25-2007 01:35 AM

The key is to check the next possible movement, ahead of the NPC, as the 'current' placement of the NPC will usually be behind in consideration with the movement.
Also, if you have the car turning, what I did was do multiple checks along the front of the car, from say, the left bumper to the right. If there is any check that is onwall, stop the movement.

JkWhoSaysNi 05-25-2007 01:44 AM

Yeah, but just stopping will feel incredibly strange to anyone driving the car (depending on speed). If you drive 100mph into a wall at anything but head on you wouldn't just stop

Look at my crudely drawn attachment ;)

Depending on the angle, the car will hit the wall and go front first into the wall (A) or the corner will slide along the wall and the left side of the car will get closer to the wall (B).

cbk1994 05-25-2007 01:44 AM

I'll just post my code... JKWhoSaysNi, thanks, but that won't work with full angles (I think?)

PHP Code:

//#CLIENTSIDE
function onCreated()
{
  
this.speed 2;
  
this.car false;
  
setTimer0.05 );
}
function 
getMoveX()
{
  return 
player.+ ( this.mspeed sinthis.ang ) );
}
function 
getMoveY()
{
  return 
player.+ ( this.mspeed costhis.ang ) );
}
function 
getMoveDX()
{
  return 
player.+ ( sinthis.ang ) );
}
function 
getMoveDY()
{
  return 
player.+ ( costhis.ang ) );
}
function 
willCrash()
{
  
temp.movex getMoveX();
  
temp.movey getMoveY();
  
  if ( 
onwalltemp.movextemp.movey ) )
  {
    return 
true;
  }
  if ( 
onwalltemp.movex 1temp.movey ) )
  {
    return 
true;
  }
  if ( 
onwalltemp.movex 1temp.movey ) )
  {
    return 
true;
  }
  if ( 
onwalltemp.movextemp.movey ) )
  {
    return 
true;
  }
  if ( 
onwalltemp.movextemp.movey ) )
  {
    return 
true;
  }
  
  if ( 
onwalltemp.movex 3temp.movey ) )
  {
    return 
true;
  }
  if ( 
onwalltemp.movex 2temp.movey ) )
  {
    return 
true;
  }
  if ( 
onwalltemp.movextemp.movey ) )
  {
    return 
true;
  }
  if ( 
onwalltemp.movextemp.movey ) )
  {
    return 
true;
  }
}
function 
doHonk()
{
  
player.attr[8] = "eb_sound-honk.gani";
  
scheduleevent.2"ClearHorn""" );
}
function 
newCheck()
{
  
temp.movex getMoveX();
  
temp.movey getMoveY();
  
s1 = ( onwall2temp.movextemp.movey abs(vecx(this.dir)),1,1)) ? 10;
  
s2 = ( onwall2temp.moveyy+vecy(this.dir)+vecy(this.dir)+abs(vecx(this.dir)*2),1,1)) ? 10;
}
function 
onClearHorn()
{
  
player.attr[8] = "";
}
function 
setDir()
{
  
temp.movex getMoveDX();
  
temp.movey getMoveDY();
  
player.dir getdirtemp.movex player.xtemp.movey player.);
}
function 
checkCar()
{
  
player.attr[7] = this.ang;
  
client.car_angle this.ang;
  
setAni"sit"NULL );
  
disabledefmovement();
  
temp.movex getMoveX();
  
temp.movey getMoveY();
  
  if ( 
keydown) )
  {
    
this.ang += .1;
    
setDir();
  }
  if ( 
keydown) )
  {
    
this.ang -= .1;
    
setDir();
  }
  if ( 
keydown232true ) )
  {
    
doHonk();
  }
  if ( 
keydown) )
  {
    if ( 
this.mspeed > -)
    {
      
this.mspeed -= .2;
    }
  }

  if ( 
keydown) )
  {
    if ( 
this.mspeed this.speed )
    {
      
this.mspeed += .05;
    }
  }
  else
  {
    if ( 
this.mspeed )
    {
      
this.mspeed -= .1;
      if ( 
this.mspeed )
      {
        
this.mspeed 0;
      }
    }
    if ( 
this.mspeed )
    {
      
this.mspeed += .1;
      if ( 
this.mspeed )
      {
        
this.mspeed 0;
      }
    }
  }
  
temp.movex getMoveX();
  
temp.movey getMoveY();
  if ( 
willCrash() == false )
  {
    
player.temp.movex;
    
player.temp.movey;
  }
  else
  {
    
this.mspeed = - .5;
  }
  
//player.chat = "Speed:" SPC this.mspeed;
  //player.chat = format( "Angle: %s Move X: %s Move Y: %s", this.ang, temp.movex, temp.movey );
}
function 
onTimeOut()
{
  if ( 
this.car == true )
  {
    
checkCar();
    
player.attr[6] = "eb_car.gani";
  }
  else
  {
    
player.attr[6] = "";
    
enabledefmovement();
  }
  
setTimer0.05 );
}
function 
onPlayerChats()
{
  if ( 
player.chat == "/car on" )
  {
    
this.car true;
  }
  if ( 
player.chat == "/car off" )
  {
    
this.car false;
  }


That's not what the car will be like in the end, I just need the basic moving, turning, wall checking.

DustyPorViva 05-25-2007 01:46 AM

Quote:

Originally Posted by JkWhoSaysNi (Post 1311602)
Yeah, but just stopping will feel incredibly strange to anyone driving the car (depending on speed). If you drive 100mph into a wall at anything but head on you wouldn't just stop

Look at my crudely drawn attachment ;)

Depending on the angle, the car will hit the wall and go front first into the wall (A) or the corner will slide along the wall and the left side of the car will get closer to the wall (B).

Just have the car blow up. :)

JkWhoSaysNi 05-25-2007 01:58 AM

Quote:

Originally Posted by cbkbud (Post 1311603)
I'll just post my code... JKWhoSaysNi, thanks, but that won't work with full angles (I think?)

That's not what the car will be like in the end, I just need the basic moving, turning, wall checking.

That should work. You have the right idea at least, checking the next place the car is going to move.

What's wrong with it at the moment?

cbk1994 05-25-2007 02:00 AM

Get on Tales and try it ... The server Tales, I'm on now. You can see for yourself.

zokemon 05-25-2007 06:58 AM

onwall2() might have been fixed up a little better but otherwise, I suggest onwall() personnally as I have always found it to be way more accurate in my wall checks.

xAndrewx 05-25-2007 08:33 AM

HTML Code:

function getMove(playersPosition)
{
  return player.(@ temp.playersPosition) + ( this.mspeed * sin( this.ang ) );
}
function getMoveD(playersPosition)
{
  return player.(@ temp.playersPosition) + ( 1 * sin( this.ang ) );
}

Easier...

cbk1994 05-25-2007 01:53 PM

Quote:

Originally Posted by xAndrewx (Post 1311714)
HTML Code:

function getMove(playersPosition)
{
  return player.(@ temp.playersPosition) + ( this.mspeed * sin( this.ang ) );
}
function getMoveD(playersPosition)
{
  return player.(@ temp.playersPosition) + ( 1 * sin( this.ang ) );
}

Easier...

Which is almost exactly what I did o.O

Kristi 05-25-2007 04:44 PM

Quote:

Originally Posted by zokemon (Post 1311705)
onwall2() might have been fixed up a little better but otherwise, I suggest onwall() personnally as I have always found it to be way more accurate in my wall checks.

there is nothing wrong with onwall2 if used correctly, and its less strain on the system

Admins 05-25-2007 06:56 PM

Quote:

Originally Posted by zokemon (Post 1311705)
onwall2() might have been fixed up a little better but otherwise, I suggest onwall() personnally as I have always found it to be way more accurate in my wall checks.

onwall2() should always work fine, both are doing pixel-accurate checks on clientside and image-rectangle check on server, or checking the covered tiles.
For car movement it can be better to use onwall() though, since you need to do several checks to detect how you are touching the wall. It is especially quite some work to detect diagonal walls like on Zone, it is working most of the time but when the bike is fast it is getting harder since doing pixel-accurate checks on the whole shape of the bike is too slow.

zokemon 05-25-2007 09:19 PM

Quote:

Originally Posted by Stefan (Post 1311793)
onwall2() should always work fine, both are doing pixel-accurate checks on clientside and image-rectangle check on server, or checking the covered tiles.
For car movement it can be better to use onwall() though, since you need to do several checks to detect how you are touching the wall. It is especially quite some work to detect diagonal walls like on Zone, it is working most of the time but when the bike is fast it is getting harder since doing pixel-accurate checks on the whole shape of the bike is too slow.

I probably was thinking of diagonal checks then. I just remember having trouble when I scripted my trigonometric movement using onwall2(). But hey, if onwall2() works better, use it! :)

Deadly_Killer 05-25-2007 10:41 PM

Hmm, it would be cool if stefan made an onwall check public function. (release in gscript -- not hard-coded)

EX:

PHP Code:

player.checkWall(txty); 

and then it would check the appropriate sides of the wall for a regular movement system.

zokemon 05-25-2007 10:45 PM

Quote:

Originally Posted by Deadly_Killer (Post 1311840)
Hmm, it would be cool if stefan made an onwall check public function. (release in gscript -- not hard-coded)

EX:

PHP Code:

player.checkWall(txty); 

and then it would check the appropriate sides of the wall for a regular movement system.

I have one if people would like to have it. It is more hardcoded into my "doMovePlayer()" function though. It has 100% perfect onwall checks and emulates the default Graal movement exactly with an added variable of speed (I tested it at a rate of 5000 tiles per second and did not cross a single wall).

cbk1994 05-25-2007 10:49 PM

Please post the code! I love you <3

Deadly_Killer 05-25-2007 11:01 PM

Quote:

Originally Posted by zokemon (Post 1311843)
I have one if people would like to have it. It is more hardcoded into my "doMovePlayer()" function though. It has 100% perfect onwall checks and emulates the default Graal movement exactly with an added variable of speed (I tested it at a rate of 5000 tiles per second and did not cross a single wall).

At such speeds, it might not even be able to move then haha.

I use loriel's check, it works fine but too fast makes it so you can't go close to the wall =[

zokemon 05-25-2007 11:34 PM

Quote:

Originally Posted by Deadly_Killer (Post 1311851)
At such speeds, it might not even be able to move then haha.

I use loriel's check, it works fine but too fast makes it so you can't go close to the wall =[

Yeah, mine will butt you up right against the wall even at such speeds.

Deadly_Killer 05-25-2007 11:38 PM

Quote:

Originally Posted by zokemon (Post 1311859)
Yeah, mine will butt you up right against the wall even at such speeds.

Oh, so if the speed > how many tiles, you just make it touch the wall. lol

zokemon 05-25-2007 11:41 PM

Quote:

Originally Posted by Deadly_Killer (Post 1311860)
Oh, so if the speed > how many tiles, you just make it touch the wall. lol

Exactly.
I don't do it that simple though, I have it do a do-while loop which moves the player every single tile. It seems to be the most effecient way.

Chompy 05-26-2007 12:17 AM

Quote:

Originally Posted by zokemon (Post 1311843)
I have one if people would like to have it. It is more hardcoded into my "doMovePlayer()" function though. It has 100% perfect onwall checks and emulates the default Graal movement exactly with an added variable of speed (I tested it at a rate of 5000 tiles per second and did not cross a single wall).



Quote:

Originally Posted by cbkbud (Post 1311849)
Please post the code! I love you <3

:O

zokemon 05-26-2007 12:19 AM

Quote:

Originally Posted by cbkbud (Post 1311849)
Please post the code! I love you <3

Oh, I didn't see your post. ^^
I'll post it in the code gallery and link it from here a little later after I spice it up (gotta remove some server specific things from the function first)

Chompy 05-26-2007 12:20 AM

Quote:

Originally Posted by zokemon (Post 1311905)
Oh, I didn't see your post. ^^
I'll post it in the code gallery and link it from here a little later after I spice it up (gotta remove some server specific things from the function first)

<3


All times are GMT +2. The time now is 05:11 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.