How to make a graf's coords adjusted to player's position

Need help with any SMBX game-related issues? Ask your questions here.

Moderator: Userbase Moderators

John Nameless
2025 Egg Hunter
2025 Egg Hunter
Posts: 130
Joined: Mon Jul 10, 2023 11:40 pm
Flair: vidio gaem

How to make a graf's coords adjusted to player's position

Postby John Nameless » Mon Aug 11, 2025 11:32 am

So im trying to make a graf, move it's x coords at the same speed to where the player is moving, making it not able to go offscreen.

However using the solo "speedX/Y" values included is not accurate to the player speed for some reason, & using the included "x/y" values makes it vanish completely, & trying to use the v.parameter stuff seems to not make the extra-setting code set not work at all.

Is there any better method on doing the title above?

Image

deice
Rocky Wrench
Rocky Wrench
Posts: 637
Joined: Fri Jul 23, 2021 7:35 am

Re: How to make a graf's coords adjusted to player's position

Postby deice » Mon Aug 11, 2025 12:27 pm

John Nameless wrote:
Mon Aug 11, 2025 11:32 am
So im trying to make a graf, move it's x coords at the same speed to where the player is moving, making it not able to go offscreen.
if i'm understanding you correctly, you want the graf to follow the player's position, right? you might want something like this:

Code: Select all

x = max(npc.sectionObj.boundary.left, min(npc.sectionObj.boundary.right - npc.width, (player.x + player.width * 0.5 - npc.width * 0.5))) - npc.spawnX;
y = 0;
just make sure to have the following inside the graf's npc config file:

Code: Select all

setpos=0
blocks=0
relativecoords=0
if you want something more involved (such as, the graf has a smooth transition to the player's x coordinate instead, or it continues moving), that's going to be more complex and might require additional lua

John Nameless
2025 Egg Hunter
2025 Egg Hunter
Posts: 130
Joined: Mon Jul 10, 2023 11:40 pm
Flair: vidio gaem

Re: How to make a graf's coords adjusted to player's position

Postby John Nameless » Tue Aug 12, 2025 9:27 am

deice wrote:
Mon Aug 11, 2025 12:27 pm
John Nameless wrote:
Mon Aug 11, 2025 11:32 am
yup that works well enough, thanks deice!


Return to “Help and Support”

Who is online

Users browsing this forum: No registered users and 4 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari