Page 1 of 1

follow and flee scripts

Posted: 8 Jan 2018, 22:50
by Ariinui
those scripts are my very first scripts created from nothing they allow an nc to follow or flee the character(s)

here they are:
the "follow"
Spoiler
With npc(sysval(Param1))
If ( Char(1).x - .x)^2 < ( Char(2).x - .x)^2 then
If Char(1).x - .x > 0 then
.facing =0
else
.facing =1
End if
Else
If Char(2).x - .x > 0 then
.facing =0
else
.facing =1
End if
End if

the "flee":
Spoiler
With npc(sysval(Param1))
If ( Char(1).x - .x)^2 < ( Char(2).x - .x)^2 then
If Char(1).x - .x > 0 then
.facing =1
else
.facing =0
End if
Else
If Char(2).x - .x > 0 then
.facing =1
else
.facing =0
End if
End if

now, let me explain how they are working
first, the script determine wich player's the nearest from the npc then it'll change the npc's facing so the npc will always "walk" in the character's direction (or the opposite direction in the "flee" script

I should also mention the two problems with this script:
1- it only check the X axis of the player so it's not the best for a level with many height
2- if the player stand on or under the npc, the npc became a little glitchy

I hope this can be usefull ^^

Posted: 19 Jan 2018, 0:59
by Eri7
Nice , this might be useful for me.

Posted: 19 Feb 2018, 2:01
by Toy Bonnie
Thanks, now i can finally remake the Deep Cheep & Eep Cheep From NSMBWii

Posted: 19 Feb 2018, 5:06
by EmeraldMaster777
How do you make the scripts work with the npc?

Posted: 19 Feb 2018, 18:25
by Toy Bonnie
EmeraldMaster777 wrote:How do you make the scripts work with the npc?
I Know! Use event "Level - Start - Others - Script"

Posted: 19 Feb 2018, 20:10
by Ariinui
Toy Bonnie wrote:
EmeraldMaster777 wrote:How do you make the scripts work with the npc?
I Know! Use event "Level - Start - Others - Script"
no, you use the npc's settings
Image
use the parallel execution too

Posted: 20 Feb 2018, 2:43
by Toy Bonnie
Ariinui wrote:
Toy Bonnie wrote:
EmeraldMaster777 wrote:How do you make the scripts work with the npc?
I Know! Use event "Level - Start - Others - Script"
no, you use the npc's settings
Image
use the parallel execution too
Ohhh i get it

Posted: 12 Jun 2018, 16:43
by WellyGames
Toy Bonnie wrote:
Ariinui wrote:
Toy Bonnie wrote:
EmeraldMaster777 wrote:How do you make the scripts work with the npc?
I Know! Use event "Level - Start - Others - Script"
no, you use the npc's settings
Image
use the parallel execution too
Ohhh i get it

:facepalm: