Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-23-2007, 01:04 PM
DrakilorP2P DrakilorP2P is offline
Registered User
DrakilorP2P's Avatar
Join Date: Apr 2006
Posts: 755
DrakilorP2P is just really niceDrakilorP2P is just really nice
Quote:
Originally Posted by Angel_Light View Post
EDIT: How would I reset setTarget()? I've tried a few different method but the player spazzes out or just head north east. :/ Also I tried to make it so the players normal movement isnt afftected by this aswell and failed... any pointers to get me started?
disabledefmovement();

this.stopped = true; or setTarget(player.x+1.5, player.y+.2).
The latter may or may not work, but it looks neater.
Reply With Quote
  #2  
Old 03-24-2007, 12:22 AM
Angel_Light Angel_Light is offline
Varia Developer
Angel_Light's Avatar
Join Date: Nov 2005
Location: Knoxville, TN
Posts: 1,684
Angel_Light is on a distinguished road
Send a message via AIM to Angel_Light Send a message via MSN to Angel_Light
Quote:
Originally Posted by DrakilorP2P View Post
disabledefmovement();

this.stopped = true; or setTarget(player.x+1.5, player.y+.2).
The latter may or may not work, but it looks neater.
tried player goes to north west
__________________
Deep into the Darkness peering...
Reply With Quote
  #3  
Old 04-10-2007, 11:54 AM
middo middo is offline
VHE Monkey
middo's Avatar
Join Date: Aug 2002
Location: California
Posts: 327
middo is on a distinguished road
Send a message via AIM to middo
I did a little modification so that it works with arrow keys

There was also a bug in the condition before your getdir(speed.x,speed.y)
You had &&'d it, and so it wouldn't update the direction if you were only moving one way. Just replace && with || like I did here.

EDIT: I changed a lot of the code. There were a lot of problems, I tested it with a friend and when we collided, we were stuck on each other! Now you can get out of walls and not fly through them if moving fast (only does the save check if you are stuck in a wall, otherwise you can still have a high speed set and the raytrace won't skip the wall)

LAST EDIT:
I fixed my own bugs and made it work almost perfectly! A saveCheck is set and overrides the speeds to try and get you out of the wall. Works perfectly for me
If you want to use it for mouse still, just uncomment the mouse lines I took out.

PHP Code:
//#CLIENTSIDE

//**************************************************
function onCreated()
{
  
this.baseSpeed 8;
  
this.acceleration 4.5;
  
this.baseFriction .5;
  
  
this.target.player.1.5;
  
this.target.player.2;
  
  
onTimeout();
  
  
disabledefmovement();
}

function 
onPlayerEnters()
{
  
disabledefmovement();
  
this.target.player.1.5;
  
this.target.player.2;  
}


//**************************************************
function onTimeout()
{
  
modY=0;
  
modX=0;
  if (
keydown(0))    modY=-1.2;
  if (
keydown(1))    modX=-1.2;
  if (
keydown(2))    modY=1.2;
  if (
keydown(3))    modX=1.2;

  if (
modY != || modX != 0SetTarget(player.x+1.5+modX,player.y+2+modY);  
  
  
// *****Set target position so we know where to move
  //if (leftmousebutton) {
  //  SetTarget(mousex, mousey);
  //}
  
  // *****Friction (We aren't walking on ice)
  
this.speed.*= this.baseFriction;
  
this.speed.*= this.baseFriction;
  
  
// *****Accelerate so we'll eventually reach that target position.
  
if (Distance(this.target.player.1.5this.target.player.2) > && !this.stopped) {
    
temp.angle getangle(this.target.player.1.5this.target.player.2);
    
temp.speed.cos(temp.angle) * this.acceleration;
    
temp.speed.= -sin(temp.angle) * this.acceleration;
    
    
Accelerate(temp.speed.xtemp.speed.ythis.baseSpeed);
    
setani("walk""");
  }
  else
  {
    if (
this.speed.0.1 && this.speed.> -0.1this.speed.0;
    if (
this.speed.0.1 && this.speed.> -0.1this.speed.0;
    
this.stopped true;
  }
  
  
// *****Actually move the player according to current speed.
  
Move(this.speed.xthis.speed.y);
  if (
this.speed.!= || this.speed.!= 0player.dir getdir(this.speed.xthis.speed.y);
  if ((
modX == && modY == 0) && (this.speed.!=|| this.speed.!=0)) 
  {
  
this.stopped == true;
  
SetTarget(player.x+1.5,player.y+2);
    
//Hack
  
if (tiletype(player.1.5player.2) == 3) {
    
setani("sit""");
  } else {
      
setani("idle""");
    }
  }
  
  
setTimer(0.05);
}


//**************************************************
/*function onMouseDown(button)
{
  // Set target position so we know where to move.
  if (button == "left") {
    SetTarget(mousex, mousey);
  }
}*/


//**************************************************
// Set the position the system will try to reach.
function SetTarget(targetxtargety)
{
    if (
Distance(targetx player.1.5targety player.2) > 1) {
      
this.target.targetx;
      
this.target.targety;
      
this.stopped false;
    }
}


//**************************************************
// Increase the speed in pixels per frame.
function Accelerate(xSpeedySpeedmaxSpeed)
{
  
  if (
Distance(this.speed.xthis.speed.y) < maxSpeed || (Distance(this.speed.xSpeedthis.speed.ySpeed) - Distance(this.speed.xthis.speed.y)) <= 0) {
//    if (modX != 0 || modY != 0) {
    
this.speed.+= xSpeed;
    
this.speed.+= ySpeed;
//    }
    
if (Distance(this.speed.xthis.speed.y) > maxSpeed) {
      
temp.angle getangle(this.speed.xthis.speed.y);
      
this.speed.cos(temp.angle) * maxSpeed;
      
this.speed.= -sin(temp.angle) * maxSpeed;
    }
  }
}

//**************************************************
// Move the player by specified amount of pixels.
function Move(xSpeedySpeed)
{
  
//if (!isapplicationactive) return;
  
  
xSpeed xSpeed<0?int(xSpeed)+1:int(xSpeed);
  
ySpeed ySpeed<0?int(ySpeed)+1:int(ySpeed);
  
  
temp.saveCheck onwall2(player.x+1,player.y+2,1,1); // modify our detection to get unstuck if we are
  
  // --- 'x' movement of the player --- \\
  
if (xSpeed != 0) {
    
temp.xDir = (abs(xSpeed) / xSpeed);
    
temp.int(player.16);
    
temp.scanx 0;
    for (
i=0< (temp.saveCheck .45 abs(xSpeed)); ++ ) {
      if (!
onwall2((temp.x+(i*temp.xDir)) / 16 + (temp.xDir*(temp.saveCheck 24 8)) * (1/16), player.211)) temp.scanx++;
      else if (
temp.saveCheck) continue; else break;
    }
    
temp.x+=(temp.scanx*temp.xDir);
    
player.temp.16;
  }
  
  
// --- 'y' movement of the player --- \\
  
if (ySpeed != 0) {
    
temp.int(player.16);
    
temp.yDir = (abs(ySpeed) / ySpeed);
    
temp.scany 0;    
    for (
i=0i<(temp.saveCheck .45 abs(ySpeed)); i++) {
      if (!
onwall2(player.1, (temp.y+(temp.scany*temp.yDir)) / 16 + (temp.saveCheck 1.5 2) + (temp.yDir*(temp.saveCheck 24 1)) * (1/16), 11)) temp.scany++;
      else if (
temp.saveCheck) continue; else break;
    }
    
temp.y+=(temp.scany*temp.yDir);
    
temp.varia=onwall2(player.x+1,player.y+2,1,1);
    
player.temp.16;
  }
  if (
tiletype(player.1.5player.2) == 3) {
    
setani("sit""");
  }  

}


//**************************************************
//Calculate the distance between (0, 0) and (dx, dy).
function Distance(dxdy)
{
  return ((
dx)^+ (dy)^2)^0.5

I'll be using this I think.
Thanks <3

Last edited by middo; 04-10-2007 at 04:04 PM..
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 07:29 PM.


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