Discord
Login
Community
DARK THEME

Need quick help with my game

Hi, im currently making a game for a schoolproject with my friend, we both are new to this platform and I just can't figure out how to get the collisions working on my game, even Open AI could't help. so if anybody knows how I could get the collisions working I'd be very thankfull. here's the linK: https://microstudio.io/i/RHin0/testing2/

if you just want a basic rectangular collider, you can just use the collisions library by going to the bottom of the list of scripts in the code section

no its a different story, maybe look at the project, I want to have a map where the grass and road tiles have a vallue of 0 for instance so i can walk through them and for trees and water for example to have a vallue of 1 or 2 so i cant walk through them

for the most efficient form, you'd have to sort all the sprites you want the player to collide with to either be a sprite sheet or a folder separate from what you want it to pass through. after that point, you can use the mapHit() function from the collisions library to check if the player is hitting a solid tile.

it would look something like this:

if keyboard.D then
  if mapHit(player.x-player.width/2,player.y,mapName).split("you'd put a : here if it's a sprite sheet and a / if it's a folder")[0] != "name of collision tiles folder or name of sprite sheet" then
    players.x += 3
  end
end

you'd repeat this for all wasd or arrow keys, changing the player.x-player.width/2 and player.y to the appropriate comparative placement so as to check up right left and down before moving.

sidenote: I noticed in your code, you used "global" to use level_width and level_height across scripts, but you don't have to do that here. good luck on the project!

thx mate i can defenitly work with this

What does .spilt do?

it separates a string into chunks based off the given text. in this scenario, "tiles:0,0".split(":") would return "tiles","0,0". you can do "tiles:0,0".split(":")[0] to only return the first chunk, "tiles". this can be used to check if a sprite is from a sprite sheet named a certain thing, and react accordingly.

...I tend to look at the documentation a lot

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community