RGSS scripting dissections and explinations
#95
In general, this thread is to help explain the basics of scripting as you might have gathered. It puts everything in layman terms, as simple as possible. Not necessarily meant for advanced mathemetics.

BUT, not to dweell over that. Most of your formula is accurate, with only a few exceptions for Ruby itself. The constant value of pi is actually just Math::PI.... all capitals. That's how it is in Ruby. And the arctan statement is part of the Math module, that being the statement of Math.atan2(y, x). It's actually in RPGMaker's help file, though you do have to dig around.

I believe, this may suffice?
Code:
dir = Math::PI * Math.atan2(Player.y - Npc.y, Npc.x - Player.x) * (180 / PI) / 180;
x+=cos(dir)*2;
y+=-sin(dir)*2;

EDIT: Edit made to PI value as noted by kyonides
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)

[Image: QrnbKlx.jpg]
[Image: sGz1ErF.png]    [Image: liM4ikn.png]    [Image: fdzKgZA.png]    [Image: sj0H81z.png]
[Image: QL7oRau.png]    [Image: uSqjY09.png]    [Image: GAA3qE9.png]    [Image: 2Hmnx1G.png]    [Image: BwtNdKw.png%5B]
  Above are clickable links
Reply


Messages In This Thread
RE: RGSS scripting dissections and explinations - by DerVVulfman - 03-18-2019, 03:18 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
   Help iwth script (RGSS Player crash) Whisper 3 9,986 06-17-2017, 05:03 PM
Last Post: Whisper
  How can I use the cmd of "require" in rgss superegp 2 7,127 11-03-2015, 06:16 AM
Last Post: kyonides
   Scripting in VX vs VX Ace Miharu 5 10,788 02-21-2015, 10:10 AM
Last Post: Taylor
   Combat animations via scripting; How? ZeroSum 2 6,102 09-20-2013, 06:58 PM
Last Post: ZeroSum
Question  RGSS stoped to work Chaos17 5 9,218 02-14-2013, 05:13 PM
Last Post: DerVVulfman
   Ruby, RGSS & General Code Discussion Kain Nobel 6 12,842 12-22-2012, 05:11 AM
Last Post: MechanicalPen
   [Request] Tut. for RGSS Eldur 9 14,219 12-07-2012, 04:27 AM
Last Post: DerVVulfman
   [ASK-RGSS] Behemoth's CBS alike Getsuga_kawaii 0 5,086 04-29-2010, 03:07 PM
Last Post: Getsuga_kawaii
   Scripting I think spazfire 7 12,083 04-12-2010, 03:21 AM
Last Post: DerVVulfman
   Beginner Scripting Tuts? KDawg08 1 4,930 03-31-2010, 11:03 PM
Last Post: Hsia_Nu



Users browsing this thread: 2 Guest(s)