Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Non-linear random movement (https://forums.graalonline.com/forums/showthread.php?t=10737)

CyanideSR71 08-30-2001 02:48 AM

Non-linear random movement
 
Hey guys, does anyone know how to make NPCs move in a curved form, but randomly throughout the level? The onwall would also be helpful for that too... If anyone can help, thanks!

AlexH 08-30-2001 02:50 AM

so you wat an NPC that moves around a level in a wavey form and it also has to have onwall
what exactly do you need this for?

LiquidIce00 08-30-2001 03:07 AM

just do random angle and do sine + cosine .. not hard

CyanideSR71 08-30-2001 03:15 AM

Bosses and baddies, Alex...

LiquidIce, could you show me a bit more? I haven't learned geometry yet, so I don't even really know how any of that works...

CyanideSR71 08-30-2001 03:52 AM

Damnit Kai! You say a lot of stuff that almost never helps... Why not trying to teach something about it?

CyanideSR71 08-30-2001 06:49 AM

Well... I'm pretty sure you don't wanna waste all that time (if you are, I'll willing to learn), so could you teach me a little something that might help, or point out a site to teach?

LiquidIce00 08-30-2001 07:21 AM

Quote:

Originally posted by Kaimetsu
LiquidIce's is the standard way, but it won't be truly random and it'll look strange at certain angles. But without delving into more advanced maths, it's probably the best way.
if it was me ..
I would do an array of next movements.. like I would randomize an angle then I would check prolly 5 steps more with that same angle (or angle -1 for each step or whatever)
then I would do onwall check to make everything is fine and walk it thru the array.
so you would do curves..

Vinvect 08-30-2001 08:52 AM

yea mee too
 
1 Attachment(s)
i saw like this.blah=cos blah blah
this.blah=sin blahblahblahi need help too
what cos and sin is
:megaeek: :megaeek: :megaeek: :grrr: :grrr: :grrr:
oh yeah heres a pic (Really good)

CyanideSR71 08-30-2001 08:57 AM

Bah, I know that Vinvect... I just don't understand what LiquidIce is talking about.

Slaktmaster 08-30-2001 04:25 PM

Hmm it shouldn't be that hard, i could help you cyanide if you do the onwall stuff... Or more like maybe I could help you. :p

CyanideSR71 08-30-2001 09:11 PM

I know that Kai... But can't you point out where I could learn, or at least start off? Or a script you've made that includes this that I can study from?

Damn you British and you big words...

incredulous (adj) - skeptical

Admins 08-30-2001 11:24 PM

It's not really simple math

NPC Code:

radangle = random(0,2*3.14);
dx = cos(radangle);
dy = -sin(radangle);

move dx*5,dy*5,5,16;



3.14 = pi
It's dy = -sin(radangle) because when
the angle is pi/2 (90 degrees) then it should
move up, so sin(90) = 1 needs to move the
npc up which means y needs to be decreased

CyanideSR71 08-30-2001 11:37 PM

Thank you so much Stefan! =D

And Kai, never say that I can't do something... Then I'm forced to defy it :(.

CyanideSR71 08-31-2001 02:19 AM

Hehe, I learned algebra 6 years before I should have... Calculus shouldn't be too hard.

Hmmm... Stefan's script wasn't exactly what I was hoping for (but I have to say it's the shortest version of that script I've ever seen). I'm looking for something similar to the movement system of the spade boss Flagr made for Antago (not the one online, the one that was on Antago Press), as I recall from ages ago.... Anyone got that? It might be in Antago's hard drive...

LiquidIce00 08-31-2001 02:38 AM

just get random angles then use stefans script but array every single movement . so your creature walks in an actual curve not like diagonally but not really a curve.. and of course dont forget onwall^_^

LiquidIce00 08-31-2001 05:29 AM

Quote:

Originally posted by Kaimetsu


What do mean by "array every single movement"?

like if the npc is at 30,30 then you random the next 5 steps he will take using sine/cosine so its curved.. and you check for onwall of course ;)

CyanideSR71 09-01-2001 12:24 AM

Quote:

Originally posted by Kaimetsu
draw the thing towards it in a fashion akin to gravitational pull.
How would this happen?

LiquidIce00 09-01-2001 04:06 AM

Quote:

Originally posted by Kaimetsu


Urgh, that won't be very efficient. And it might not look very curvy. And it might be difficult to control in general.

no..
you get a base angle for 5 steps
like for example its 1.07 then you random out value between
-.2,.2 so if it gets a 0 then it just walks diagonally .. if u get a -.2 then it will walk a up curve or whatever or a positive a down curve. would work fine ;)

LiquidIce00 09-01-2001 04:38 AM

here i didnt actually test this i just put on graal and clicked style and test to debug it but its just a base of what I was saying (prolly buggy) and i didnt do it using showcharacter either..
NPC Code:

// NPC by LiquidIce

this.maxstep = 5; //step length

if (playerenters&&isleader) {
init();
timeout=.1;
}

function init() {
setarray stepx,this.maxstep+1;
setarray stepy,this.maxstep+1;
for (this.i=0;this.i<this.maxstep;this.i++) {
stepx[this.i]=x;
stepy[this.i]=y;
}
}

if (timeout) {
if (stepx[0]=0||stepy[0]=0) {
randomstep();
}
else {
move();
movearray();
}
timeout=.1;
}

function move() {
x=stepx[0];
y=stepy[0];
}

function movearray() {
for (this.i=this.maxlength;this.i>=0;this.i=this.i-1) {
stepx[this.i]=stepx[this.i-1];
stepy[this.i]=stepy[this.i-1];
}
}

function randomstep() {
this.angle=random(0,6.28);
this.effect=random(-.2,.2);
for (this.i=0;this.i<this.maxstep;this.i++) {
this.x=sin(this.angle);
this.y=cos(this.angle);
if (this.i=0) { this.x+=x-.5;this.y+=y-.5; }
else {
this.x+=stepx[this.i-1]-.5;
this.y+=stepy[this.i-1]-.5;
}
if (onwall(this.x,this.y)) {
break;
}
stepx[this.i]=this.x;
stepy[this.i]=this.y;
this.angle+=this.effect;
}
}


CyanideSR71 09-02-2001 05:49 AM

Wow, that was really helpful for other things, but still not quite what I need =(. Someone gimme Antago's hard drive, please...

Tyhm 09-02-2001 01:03 PM

If memory serves, all the nonlinear motion scripts he had came from me anyway, particularly the bird...

The trick is to modify this.xspeed and this.yspeed instead of x and y directly. So
if(dir=0) this.yspeed-=random(0.5,1); //try to go up - if you're going down, slow down some
//etc
while(abs(this.yspeed)>1) this.yspeed*=0.9; //maximum speed=1 tile per call
//etc
this.testy=y+this.yspeed;
//all the usual onwall: if it hits the wall, this.testy=y; this.testx=x;
y=this.testy;

You can get it from there easy. If you can't, give up, you're scripting out of your league.

LiquidIce00 09-03-2001 05:21 AM

Quote:

Originally posted by Tyhm
If memory serves, all the nonlinear motion scripts he had came from me anyway, particularly the bird...

The trick is to modify this.xspeed and this.yspeed instead of x and y directly. So
if(dir=0) this.yspeed-=random(0.5,1); //try to go up - if you're going down, slow down some
//etc
while(abs(this.yspeed)>1) this.yspeed*=0.9; //maximum speed=1 tile per call
//etc
this.testy=y+this.yspeed;
//all the usual onwall: if it hits the wall, this.testy=y; this.testx=x;
y=this.testy;

You can get it from there easy. If you can't, give up, you're scripting out of your league.

well .. my idea for nonlinear was more of a real curve instead of just moving diagonally randomly..
if thats what u ment ;\

CyanideSR71 09-03-2001 05:50 AM

But that didn't look like a curve, LiquidIce.


All times are GMT +2. The time now is 12:32 AM.

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