Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   movement formula for 'move' command (https://forums.graalonline.com/forums/showthread.php?t=53126)

Duwul 06-13-2004 08:47 PM

movement formula for 'move' command
 
I've recently created a NPC that follows a certain path. The NPC uses the move command to move, so the time it takes is required. However, I can't get it to maintain a constant speed. Does anyone know a formula that can help me out? All help is appreciated.

Loriel 06-13-2004 09:09 PM

The time should be something like (dx*dx + dy*dy)^0.5 / speed, I think.

Duwul 06-13-2004 09:15 PM

I actually had that, except I did not divide it by the speed at the end. I'll try it. Thanks.

EDIT: Well it worked. Thanks a lot! ^^

Ningnong 06-14-2004 12:23 AM

1 Attachment(s)
I have attached a baddy script - it uses the move command. I made it initially for archaic, but it should help you.

But to the point:

NPC Code:

tx = targetx - x;
ty = targety - y;
dist = (tx*tx+ty*ty)^0.5;
nx = (tx/dist)*walkspeed;
ny = (ty/dist)*walkspeed;



Edit:

Then simply use
NPC Code:

move nx,ny,walkspeed,1+4+8;



etc.

Hope It helped :cool:

Duwul 06-14-2004 05:40 AM

I guess a bit, but I'm only looking for an equation to put in 'time' of the move command, so that no matter the distance it moves, the walking speed remains the same. I am not using x+/x-/y+/y-.

Python523 06-14-2004 11:15 PM

try multiplying the distance by .05? dono

Duwul 06-16-2004 07:28 PM

Ran into a problem. I made a npc that walks in a straight line on the along the x axis and while its moving in between the 2 points, it goes very fast. I guess the equation didn't work properly =/
Can anyone help me out with one that works?

Python523 06-16-2004 09:49 PM

try somethin like this
NPC Code:

if (mousedown) {
dx = mousex - x;
dy = mousey - y;
dist = (dx^2+dy^2)^.5;
speed = dist * .05;
move dx,dy,speed,;
}



All times are GMT +2. The time now is 10:44 PM.

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