[Tea-Script] Accurately chasing projectile

Description: Internal scripting system of SMBX-38A Engine based on the simple VB-like language
Moderators: Lx Xzit, Yoshi021, 5438A38A, Semi-moderatos, Moderators

Super Mario Player M
Topic author, Duke
Duke
Avatar
Super Mario Player M
Topic author, Duke
Duke
Age: 21
Reputation: 29
Posts: 141
Joined: 23 Jun 2016
Location: Planet Earth
Youtube channel URL Tencent QQ

Post #1by Super Mario Player » 24 Jul 2016, 17:32

This script lets you make a NPC that chases you accurately and permanently.
It uses four variables, which I called time, speed, deltax and deltay. You can change the speed of the missile by changing the value of the variable "speed", be sure however to set it to anything but zero, or else it'll induce a runtime error.
To use this script:
1- In the .txt file of the NPC you wanna use as the projectile, add the following line:
scripts=chase
2- In the Script editor, create a script called "chase", and paste the following code in it:

Code: Select all

with npc(sysval(param1))
'Sets the Δy value
val(deltay)=(Char(1).Y-.Y)
'Sets the Δx value
val(deltax)=(Char(1).X-.X)
'Sets the Δt value
val(time)=(sqr(val(deltax)^2+val(deltay)^2))/val(speed)
'Sets the vertical and horizontal speed values
.Ysp=val(deltay)/val(time)
.Xsp=val(deltax)/val(time)
end with

3- Create four variables, called "time", "speed", "deltax" and "deltay"
4- Set the "speed" variable to the speed you want for the projectile. Do NOT leave it at zero!
5- And then place your projectile.

That's all. I've included a test level:
homingmissile.zip
(2.08 KiB) Downloaded 268 times
My current project:
Spoiler
The Tower of Challenges

Languages (for PMs):

Image

YouTube channel:
Image
Image

Return to “TeaScript”

Who is online (over the past 5 minutes)

Users browsing this forum: 1 guest