Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » how can i put npc's on a scrolling map?
- N8_D_GR8_1
-
Scratcher
1000+ posts
how can i put npc's on a scrolling map?
That really depends on how your scrolling system works. You should share your project or give more details if you want help.
- RokCoder
-
Scratcher
1000+ posts
how can i put npc's on a scrolling map?
When dealing with a world map (i.e. something larger than the screen), everything in the game must have world coordinates. To put them into screen coordinates, you modify them in relation to the camera's position (which is often the player character's position).
For example, you may have a NPC that is at a world position of (2500, 800). With screen coordinates being -240,-180 to 240,180, this is clearly out of bounds. Consider that your player may be at world coordinates (2400, 900), this means he is actually quite near the NPC. By subtracting the camera's position from the world coordinates, you get the screen coordinates.
Using the above information, we can transform the player and NPC to local screen coordinates by subtracting the camera position -
Remember to have world coordinates for all objects in the world and to update them all to screen positions each frame.
For example, you may have a NPC that is at a world position of (2500, 800). With screen coordinates being -240,-180 to 240,180, this is clearly out of bounds. Consider that your player may be at world coordinates (2400, 900), this means he is actually quite near the NPC. By subtracting the camera's position from the world coordinates, you get the screen coordinates.
- Player is at 2400, 900
- Camera is connected to the player so is also at 2400, 900
- NPC is at 2500, 800
Using the above information, we can transform the player and NPC to local screen coordinates by subtracting the camera position -
- Player is at 2400, 900 - 2400, 900 = 0, 0 (centre of screen)
- NPC is at 2500, 800 - 2400, 900 = 100, -100 (above and to the left of the player)
Remember to have world coordinates for all objects in the world and to update them all to screen positions each frame.
- miguelgven10
-
Scratcher
10 posts
how can i put npc's on a scrolling map?
When dealing with a world map (i.e. something larger than the screen), everything in the game must have world coordinates. To put them into screen coordinates, you modify them in relation to the camera's position (which is often the player character's position).i`ll try, thank you.
For example, you may have a NPC that is at a world position of (2500, 800). With screen coordinates being -240,-180 to 240,180, this is clearly out of bounds. Consider that your player may be at world coordinates (2400, 900), this means he is actually quite near the NPC. By subtracting the camera's position from the world coordinates, you get the screen coordinates.
- Player is at 2400, 900
- Camera is connected to the player so is also at 2400, 900
- NPC is at 2500, 800
Using the above information, we can transform the player and NPC to local screen coordinates by subtracting the camera position -
- Player is at 2400, 900 - 2400, 900 = 0, 0 (centre of screen)
- NPC is at 2500, 800 - 2400, 900 = 100, -100 (above and to the left of the player)
Remember to have world coordinates for all objects in the world and to update them all to screen positions each frame.
- Discussion Forums
- » Help with Scripts
-
» how can i put npc's on a scrolling map?