03-18-2019, 03:18 AM
(This post was last modified: 03-18-2019, 03:51 AM by DerVVulfman.)
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?
EDIT: Edit made to PI value as noted by kyonides
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