Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-25-2007, 12:47 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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.
__________________
Reply With Quote
  #2  
Old 05-25-2007, 01:03 AM
JkWhoSaysNi JkWhoSaysNi is offline
Ruler of the graalaxy
Join Date: Feb 2005
Location: Great Britain
Posts: 488
JkWhoSaysNi is on a distinguished road
Send a message via ICQ to JkWhoSaysNi
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.
__________________

Coming soon (Hopefully:P)
Reply With Quote
  #3  
Old 05-25-2007, 01:12 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Depends, is your car only moving in four directions or is it capable of turning in a complete circle?
Reply With Quote
  #4  
Old 05-25-2007, 01:26 AM
JkWhoSaysNi JkWhoSaysNi is offline
Ruler of the graalaxy
Join Date: Feb 2005
Location: Great Britain
Posts: 488
JkWhoSaysNi is on a distinguished road
Send a message via ICQ to JkWhoSaysNi
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)
__________________

Coming soon (Hopefully:P)
Reply With Quote
  #5  
Old 05-25-2007, 01:35 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
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.
Reply With Quote
  #6  
Old 05-25-2007, 01:44 AM
JkWhoSaysNi JkWhoSaysNi is offline
Ruler of the graalaxy
Join Date: Feb 2005
Location: Great Britain
Posts: 488
JkWhoSaysNi is on a distinguished road
Send a message via ICQ to JkWhoSaysNi
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).
__________________

Coming soon (Hopefully:P)

Last edited by JkWhoSaysNi; 07-13-2007 at 09:49 PM..
Reply With Quote
  #7  
Old 05-25-2007, 01:44 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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.
__________________
Reply With Quote
  #8  
Old 05-25-2007, 01:58 AM
JkWhoSaysNi JkWhoSaysNi is offline
Ruler of the graalaxy
Join Date: Feb 2005
Location: Great Britain
Posts: 488
JkWhoSaysNi is on a distinguished road
Send a message via ICQ to JkWhoSaysNi
Quote:
Originally Posted by cbkbud View Post
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?
__________________

Coming soon (Hopefully:P)
Reply With Quote
  #9  
Old 05-25-2007, 01:46 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Quote:
Originally Posted by JkWhoSaysNi View Post
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.
Reply With Quote
  #10  
Old 05-25-2007, 02:00 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Get on Tales and try it ... The server Tales, I'm on now. You can see for yourself.
__________________
Reply With Quote
  #11  
Old 05-25-2007, 06:58 AM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
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.
__________________
Do it with a DON!
Reply With Quote
  #12  
Old 05-25-2007, 08:33 AM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
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...
__________________
Reply With Quote
  #13  
Old 05-25-2007, 01:53 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by xAndrewx View Post
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
__________________

Last edited by cbk1994; 05-25-2007 at 01:53 PM.. Reason: wow I can't type
Reply With Quote
  #14  
Old 05-25-2007, 04:44 PM
Kristi Kristi is offline
Bowie's Deciple
Kristi's Avatar
Join Date: Dec 2003
Location: Boston, MA
Posts: 748
Kristi has a spectacular aura aboutKristi has a spectacular aura about
Send a message via AIM to Kristi Send a message via MSN to Kristi
Quote:
Originally Posted by zokemon View Post
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
__________________
Reply With Quote
  #15  
Old 05-25-2007, 06:56 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
Quote:
Originally Posted by zokemon View Post
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.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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