Golden Sun Hacking Community
13, April, 2021, 07:27:52 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Be sure to check out gsmagic, a WIP tool that has map editing capabilities!
  Home   Forum   DC Wiki Help Search Calendar Downloads Login Register  
Pages: [1]   Go Down
Author Topic: How does Golden Sun handle movement?  (Read 3631 times)
0 Members and 1 Guest are viewing this topic.
charon the ferryman
o - - o - - o
Jupiter Clan


Regular Member

Coins: 22
Offline Offline

I am: chillin'
Posts: 189

« on: 29, August, 2016, 01:06:45 PM »

I'm not really concerned about collisions, but I'm curious to know more about how Golden Sun handles moving/rotating the sprite and movement. I want to do something similar with my current game Colors but adapt it for what I've already built out. My current game feels so jerky and it basically uses the same angle/rotation so I want to model it off of Golden Sun's engine here.

Does anyone have the code of how this is handled? Or at least a model or explanation on how it works on a logical level? Like if I wanted to port it in Java or something like that. Thanks.

View Profile WWW
Potions class is starting
Venus Clan

Death Eater+Grass Snake = Snake Eater? SNAAAAAAAKE

Veteran Member

Coins: 11
Offline Offline

Posts: 1322

« Reply #1 on: 29, August, 2016, 06:53:16 PM »

If it feels jerky, there's a few possible problems:

1) Lack of acceleration
2) Lack of necessary blend states
3) Poor camera movement

The first is easy to fix. Just give the player an initial speed for tapping the key to move, then accelerate up to their max speed as long as it remains held. The acceleration should take place over a few frames at most. When the key is released, strong friction should kick in and bring them to a stop (again, over several frames). For reversing direction, apply friction *and* the new force, resulting in a faster transition between moving in one direction to the other.

The second is a harder fix, because it's chiefly an art problem. If you already have acceleration built into the character, you may need additional blend states for going between moving and idle, or between different movement directions.

It's a little hard to tell if #3 is relevant based on your description, but if this is the case, you'll just have to fine-tune your camera bounds, smoothing speed, and so on.
« Last Edit: 29, August, 2016, 07:19:29 PM by leaf » Logged

Spoiler for quotes:
[9:00:50 PM] Randel Peltier: Ok...what did I do last night?
[9:01:19 PM] Kain: Something boring, repetitive, and lasted for about sixty seconds.
[10:45:08 AM] Salanewt: But yeah, the elemental phalluses are being... Stroked up by Saturos and co., and the energy will go towards... Mt. Muffin, where the Golden Climax will arise.
[7:28:42 PM] Salanewt: An added bonus is that Isaac and co. were trying to stop Saturos and co. because their beliefs state that Mt. Muffin should remain a virgin.
[9:54:21 PM] Randel Peltier: Guess the number in my head an you get to pick what I say. Number between 1-10
[9:54:28 PM] leaf: 11
[9:54:36 PM] Randel Peltier: @#$%!
[8:38:13 PM] Randel Peltier: Shes like this queen up on a pedastal that I have yet to court.
[8:38:29 PM] Kain: You've tried courting her.
[8:38:43 PM] leaf: and failed spectacularly
[8:38:44 PM] Randel Peltier: Ive tried...shes the best dating game ever.
[12:24:35 AM] Salanewt: I need to find a picture of a naked person to put on the Christmas tree next year.
[2:19:06 PM] Zeadra: wait... Rief's a guy???
[1:09:57 PM] Zeadra: well if you want to know if its a new effect or something weird, just check GS1, if side step is there maby it is the nimble dodge thing
[1:10:35 PM] Kioll: For once, you've contributed something useful.  o.O
View Profile
Daddy Poi's Oily Gorillas
Fox McCloud, the Hacking Doctor
Mercury Clan


Coins: 1002
Online Online

I am: certainly not a Gallant!
Clan Position: Head Gallant
Posts: 2495

« Reply #2 on: 29, August, 2016, 07:25:16 PM »

Should be easy enough to explain how the code works, maybe... (Will want to look into it again, but I'll paste the relevant documentation here.)

The NPC data in RAM... starts with an address to NPC script code... and for the PC, the data there relates to movement... so the code that refers to that, I shall list:

0802632C = Data Script 23 - Hover
 08026362 = Hover running speed
 08026368 = Hover initial running speed/end traction
 0802636E = Hover running animation
 08026374 = Hover walking speed
 0802637A = Hover initial walking speed
080267BC = Data Script 24 - Slippery Ground
 080267EC = Slippery running speed
 080267F4 = Slippery initial running speed (lower traction means that it takes longer to reach full speed)
 080267FA = Slippery running animation
 08026802 = Slippery walking speed
 0802680A = Slippery initial walking speed (lower traction means that it takes longer to reach full speed)
08026DD0 = Sets psynergy to use on map. (At least for shortcuts.)
08026E60 = Related to button controls and menus?
08026F80 = Collision detection? Removing the code makes it so you can’t move without holding L in debug mode
08026FC8 = (BL in Data Script 19)?
08027064 = Data Script 19 - Normal movement - Gives you the ability to move your character.
 080270A6 = Running speed
 080270AE = Initial running speed (starts at this before changing to normal value)
 080270B2 = Running animation
 080270BA = Walking speed
 080270C2 = Initial walking speed (starts at this before changing to normal value)
 0802726E = Debug mode: Walk through walls
 080276A2 = Pushing NPCs animation (not used in all instances, such as with pushing psynergy obstacles)
 080276C2 = Idle animation (not moving)
 080276C8 = Idle animation when party leader has 0 HP
080279B0 = Data Script 1A - Overworld movement
 080279DE = Running speed
 080279E4 = Initial running speed
 080279EA = Running animation
 080279F0 = Walking speed
 080279F6 = Initial walking speed
 08027A50 = Debug mode: Walk through walls (There’s also a Flag 0x163 check. (Can be used instead of the L button, if necessary.)
08027E0C = Data Script 25 - Calls 08026E60 - No movement. Access to menus/psynergy shortcuts.
08027E20 = Data Script 1F - Overworld thing; walk through everything, objects are solid
 08027E38 = Debug mode: L button check that doesn’t seem to do anything special?
 08027FAA = Debug mode: Walk through walls
08028534 = Data Script 20 - Ship mode
 08028608 = Debug mode: L button check
08028AAC = Data Script 21 - Hover Ship mode
 08028B96 = Debug mode: L button check
080290F4 = Data Script 1B - Climbing wall
 0802910A = Debug mode (Nothing special?)
 08029110 = Idle climbing animation (when not moving)
 0802914C = Climbing right animation
 08029156 = Climbing left animation
 0802915E = Climbing up/down animation
 0802920E = Hitting wall/dead end animation
 08029262 = Animation before climbing up/hitting ground
080292FC = Data Script 1C - Climbing rope
08029570 = Data Script 1D - Walking rope
08029810 = Unused? Loads a value from 02000474
080298C0 = Data Script 1E - Sand
 080299A2 = Debug mode (Nothing special?)
 08029C94 = Debug mode: L button check
0802A124 = Data Script 22 - Sand (World Map)
 0802A1BC = Debug mode: L button check
Well, not everything about all of them are detailed, but I hope this will help you get an idea. (And assuming you know assembly, then you can see instruction for instruction what is going on.)
« Last Edit: 29, August, 2016, 07:28:23 PM by Fox » Logged

Golden Sun Docs: Broken Seal - The Lost Age - Dark Dawn | Mario Sports Docs: Mario Golf & Mario Tennis | Misc. Docs
Refer to Yoshi's Lighthouse for any M&L hacking needs...

Sometimes I like to compare apples to oranges. (Figuratively) ... They are both fruits, but which one would you eat more? (If taken literally, I'd probably choose apples.)
Maybe it is over-analyzing, but it doesn't mean the information is useless.

The only GS Discord servers with significance are:
Golden Sun Hacking Community
GS Speedrunning
/r/Golden Sun
GS United Nations
Temple of Kraden

Can you believe how small the Golden Sun Community is?

2+2=5 Don't believe me? Those are rounded decimal numbers. Take that, flat earth theorists! :)
View Profile
The last member of the Luna clan
Luna Clan

Great Member

Coins: 28
Offline Offline

I am: Timeless. As in, i don't have much free time.
Posts: 543

« Reply #3 on: 29, August, 2016, 08:59:48 PM »

Your game is in GML right?

Like leaf said. Use speed = speed + accel
and set a high friction.

In GS, AFAIK, the accel is really high and the friction as wel.

Have you looked in diagonal movement yet?

"Hear the sounds and melodies
Of rilets flowing down
They're the verlasting songs
Whispering all the time
As a warning that behind some rocks
There's a rigid grap even
Oreads fear the tread"
View Profile
charon the ferryman
o - - o - - o
Jupiter Clan


Regular Member

Coins: 22
Offline Offline

I am: chillin'
Posts: 189

« Reply #4 on: 10, September, 2016, 04:51:16 AM »

Currently I've got something down that works for now.

What I did was I built a pulley simulator for the rotation, so basically when you press down on a key, it "pulls" on a circle with a "string" in that direction until it orients it that direction. This means basically the further the orientation is from the desired rotation, the more time it needs to accelerate to get to the desired rotation. This takes place on a super small scale though so it's not really noticeable to the player.

Now comes the fun of collisions... welp.

View Profile WWW
Programmer Extraordinaire
Web Host

Fear my blades

Veteran Member

Coins: 100
Offline Offline

Gender: Male
Emblems: Website Founder
Clan Position: Creation God of Sol
Posts: 1767

« Reply #5 on: 25, September, 2016, 05:01:08 PM »

Hello again.

I actually did a lot of work on figuring out exactly how movement worked in Golden Sun.  It's been a while so my memory is pretty fuzzy, but I still have some code lying around I wrote to mimic it for my Flash tech demo.

The basic code for movement I did was separated into two functions, one for handling input for the player, and another one that EVERY character in the engine used to handle movement.

The function for the player
Note that keyDirectionHeld would be set to 1 if they corresponding key was held, and 0 if not.

xMove = keyRightHeld - keyLeftHeld;
yMove = keyDownHeld - keyUpHeld;

// Does the player want to move?
if (xMove != 0 || yMove != 0) {
dirMove = direction(0, 0, xMove, yMove); // Calculate direction player wants to move

moving = true;

if (keyRunHeld)
speedMax = 1.5; // Running max speed
speedMax = 1; // Walking max speed

if (speed > .25) {
if (keyRunHeld)
animation = 5; // Animation 5 is the running animation
animation = 2; // Animation 2 is the walking animation
} else {
animation = 9; // Animation 9 is the idle animation
dirFace = dirMove; // Force facing direction to direction player wants to move;
} else {
moving = false;
speed = 0; // Player stops immediately when buttons are released
animation = 9; // Animation 9 is the idle animation

This one handles movement of ALL characters

if (moving) {
speed += acceleration;
if (speed > maxSpeed)
speed = maxSpeed;
} else if (speed > 0) {
speed -= acceleration;
if (speed < 0)
speed = 0;

if (speed>0) {
xPrevious = x;
yPrevious = y;

// This function moves the actor the distance of "speed" in the direction of "dirMove"
// It also handles collisions, and sliding the character around obstacles
moveDirection(speed, dirMove);

// Face the character the direction they're moving
if (x != xPrevious || y != yPrevious)
dirFace=direction(xPrevious, yPrevious, x, y);  // Calculates direction between 2 points

In Golden Sun's engine, "acceleration" is 0.25 for the player.

moveDirection(distance, direction) is where the character's position is actually changed, and collisions are handled.  Here's a post I made a while back that goes into the details of how collisions work in Golden Suns engine.  There's a lot of good info later on in that topic too.

Additionally, the character's sprite facing direction is eased so they turn gradually instead of instantly.
if (dirFace != dirSprite) {
// Normalize dirFace so the sprite turns the quickest way to face correctly
if (dirFace - dirSprite > 180)
dirFace -= 360;
else if (dirFace - dirSprite <= -180)
dirFace += 360;

// Calculate direction change
dirChange = dirFace - dirSprite;
if (dirChange > 22.5)
dirChange = 22.5;
if (dirChange < -22.5)
dirChange = -22.5;

// Add direction change, normalizing output between 0 and 360
dirSprite = (dirSprite + dirChange + 360) % 360; 

I'm shaking my head in general disapproval of everything
View Profile WWW
charon the ferryman
o - - o - - o
Jupiter Clan


Regular Member

Coins: 22
Offline Offline

I am: chillin'
Posts: 189

« Reply #6 on: 27, September, 2016, 01:08:28 AM »

hoooooooooooooly crap thank you atrius you are freaking awesome

View Profile WWW
Pages: [1]   Go Up
Jump to:  

28, March, 2021, 06:10:33 PM
Salanewt: Tiny announcement down here that a new animation pack is now available for download! The Animation Overhaul is required; see the downloads page for more details.
03, March, 2021, 03:16:30 AM
Daddy Poi's Oily Gorillas: I'm happy ACE is possible and easy in GS1. :D Thank you Tret. Now if we can get GS2 Air's Rock to do ACE, wouldn't that be something.
18, February, 2021, 03:25:26 PM
Salanewt: The one here has everything:;sa=view;down=132
18, February, 2021, 02:03:20 PM
VardenSalad: It looks like Atrius' editor download is broken again. The only thing in the .zip is the background image
13, February, 2021, 03:15:41 PM
MaxiPower: Welcom back Charon. been a long time.
11, February, 2021, 09:40:04 PM
Daddy Poi's Oily GorillasSo how long is this site going to be "This website is still under construction, please excuse the mess." :D
04, February, 2021, 12:56:21 AM
charon the ferryman: LMAO i love 2010 tech
04, February, 2021, 12:56:07 AM
charon the ferryman: release me from my discord prison meme mortals
15, November, 2020, 03:45:26 PM
Salanewt: We're more alive than the board implies; most discussion takes place over on the Discord server.
15, November, 2020, 03:45:06 PM
Salanewt: Haha, heya!
15, November, 2020, 02:07:50 PM
Frog: Nice to see this place is still alive...ish anyway xD
30, October, 2020, 11:10:23 PM
Salanewt: ... Actually, it's almost time for me to post an update on the forum. It's been coming along really nicely overall, and it was only a couple months or so ago that I added some new status effects to the game.
30, October, 2020, 11:08:41 PM
Salanewt: I need to get it done to start making progress on the parts of the AI Overhaul I want to start working on.
30, October, 2020, 11:08:14 PM
Salanewt: It's going well! I wanted to get more of my djinn reform done this week but I've been busy with other things sadly.
30, October, 2020, 09:58:14 PM
KyleRunner: Hi guys! How are you doing?
13, October, 2020, 11:19:21 AM
MaxiPower: first chapter of my golden sun inspired webtoon is now live. be cool if yas could check it out.
31, August, 2020, 08:40:32 AM
Daddy Poi's Oily Gorillas: Being able to convert IPS files to text files to also supporting commenting, and convert back to IPS after changes.... sounds like a fun strategy? 
27, August, 2020, 10:37:30 PM
Salanewt: Hey, thanks! 
25, August, 2020, 12:59:22 AM
Foreclosure: Yo! Looking forward for this AI OVerhaul patch when it's finished :) :) 
19, August, 2020, 07:00:17 PM
Salanewt: That's awesome! I'm pretty good; been working on an AI Overhaul project and have made some nice progress in the past couple weeks; the goal for tonight is to add Deadbeard to GS2 and then I can move onto something new.
19, August, 2020, 01:14:56 PM
Awec: Ye not bad, just checked back in for updates on GS Reloaded really. Although now I'm looking back through some of my old forum posts, which is fun :D how are you?
19, August, 2020, 01:43:07 AM
Salanewt: It sure is! How have you been?
16, August, 2020, 09:40:57 AM
Awec: Yo nice to see this forum is still going
14, August, 2020, 09:06:44 PM
Salanewt: Hey! How goes it?
01, August, 2020, 01:31:53 PM
KyleRunner: Hello, people!
08, July, 2020, 08:57:11 PM
Salanewt: That awkward feeling when almost a quarter of a year goes by without anyone posting a message in this chatbox.
27, April, 2020, 07:54:10 PM
Daddy Poi's Oily Gorillas: I'm having a thought. So I know Atrius's editor is slow at saving sprites.... So I've been thinking.   I am considering another console program.  This time, for importing and exporting sprites/animations. Image files (for sprites), binary files (for animation data), and maybe binary or text files for Settings. Would certainly be cool if it works out. - Console programs are fun, when you can (at least temporarily) cheat out making a full interface editor for them. =P
25, April, 2020, 10:42:07 PM
Daddy Poi's Oily Gorillas: Tried to list those in order of importance, but anyway....
25, April, 2020, 10:37:59 PM
Daddy Poi's Oily Gorillas: GSHC, GS Speedrunning, /r/Golden Sun, GS United Nations, ToK.  Sixth one is border-line I'm not sure.
25, April, 2020, 08:00:21 PM
Daddy Poi's Oily Gorillas: (low as in <100)

Temple of Kraden Golden Sunrise
Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.072 seconds with 22 queries.