Adding Collisions and Walls (from Tiled) to your Love2D Game

  Рет қаралды 36,807

Challacade

Challacade

Күн бұрын

Пікірлер: 102
@YoshimiGames
@YoshimiGames 3 жыл бұрын
This is such a fantastic series. Concise and to the point videos, very well explained. I'd love to see more (objects, doors to new maps, enemies, combat, animated tiles etc!!). Following your tutorials I've got the beginnings of a game I hope to port over to the Playdate when it arrives.
@Bub.tv21
@Bub.tv21 10 ай бұрын
Easiest thing to add is animated tiles. You can do this by in your love.update function add "GameMap:update(dt)" gamemap should be replaced with what your level variable is named then in tiled find the animation button and add the animation to your tiled and thats it!
@geoffpaulsen
@geoffpaulsen Жыл бұрын
Great Series @Challacade. Around minute 3:20, it might be useful to note that for the Player Colider, one could calculate the width and height, based on the sprite pixels and the scale factor.
@gwrydd
@gwrydd Жыл бұрын
very helpful! for others finding this now like i am. in the for loop he uses "pairs" instead use "ipairs" as it is much faster. the same goes for table.insert it is slower than doing walls[#walls+1] = wall when doing anything that can affect yout performance its always best to use tricks to improve performance
@shamsparvezarka1860
@shamsparvezarka1860 Жыл бұрын
This video is a lifesaver
@beatrz3
@beatrz3 2 жыл бұрын
hi in around 12:55 i tried to load the code and it says that the line "local wall = world:newRectangleCollider(obj.x, obj.y, obj.width, obj.height)" is wrong how can i fix it?
@Challacade
@Challacade 2 жыл бұрын
What does the error actually say? One thing you could try is deleting the Wall object layer in Tiled, and creating it again. Sometimes some wall objects with 0 width and 0 height get added by mistake
@beatrz3
@beatrz3 2 жыл бұрын
@@Challacade ty very much it worked now:)
@gamerule36
@gamerule36 Жыл бұрын
thanks so much this also fixed my problem @@beatrz3
@pokeman5796
@pokeman5796 3 жыл бұрын
Great video🔥thank you for the upload.
@BrandonS-lk2qc
@BrandonS-lk2qc 3 жыл бұрын
Thank you for doing this!
@big_swivel
@big_swivel 2 жыл бұрын
How would I approach checking if the player collides with a certain collider?
@MirralisDias
@MirralisDias Жыл бұрын
Is it possible to place a collider on the tree's sprite in advance, so that when you place trees in the Tiled editor, they already come with the collider attached?
@idoblenderstuffs
@idoblenderstuffs 2 жыл бұрын
pleeeease continue this tutorial series
@marcuslangebeck3820
@marcuslangebeck3820 2 жыл бұрын
i have a question.. I will try to tell my script to start my player in another place.. so, i change the player.x and player.y .. but nothing happens.. ? Is that nok the right way?
@Abiiiiiiiiiiiiii06
@Abiiiiiiiiiiiiii06 Жыл бұрын
How can I add the wall collisons using bump instead? Windfield is very laggy
@trouble6043
@trouble6043 Жыл бұрын
12:34 for me I get this error in the for loop: Error Libraries/windfield/init.lua:745: Box2D assertion failed: area > b2_epsilon Traceback [love "callbacks.lua"]:228: in function 'handler' [C]: in function 'newFixture' Libraries/windfield/init.lua:745: in function 'newRectangleCollider' main.lua:16: in function 'load' [love "callbacks.lua"]:136: in function [C]: in function 'xpcall' [C]: in function 'xpcall' Could Someone please help me!
@Chipichipichapachapadubidubid
@Chipichipichapachapadubidubid 9 ай бұрын
SAME!!
@tarunthakur6091
@tarunthakur6091 8 ай бұрын
me too
@p.rasmitadora4731
@p.rasmitadora4731 4 ай бұрын
I get a error at windfield/init.lua:207: attempt to call method getBodies() (a nil value)
@andre.gabriel
@andre.gabriel 3 жыл бұрын
Great video thanks for sharing your knowledge. 😀
@Kalebjosewitz
@Kalebjosewitz 3 жыл бұрын
Every time I lock my player x/y and my collider x/y they never match up. Idk what I’m doing wrong
@ATS-uy4vl
@ATS-uy4vl 2 жыл бұрын
Do the following, put (x - width / 2) in player's X position, this also equates to Y position
@stinkyseastar3560
@stinkyseastar3560 Жыл бұрын
@@ATS-uy4vl hey could you explain that in more detail? I don't understand
@ATS-uy4vl
@ATS-uy4vl Жыл бұрын
@@stinkyseastar3560 From what I remember at the time, I meant that if you subtract the X/Y position from half the width/height, the Collider will snap to the sprite
@Benox-Dev
@Benox-Dev 2 ай бұрын
THX for the amazing series ! can you add more tutorials for main menu and game over pls
@Retro1c
@Retro1c 2 ай бұрын
i have a problem, for some reason the bsg rectangle positions at the bottom right corner of the player sprite, how do i fix that?
@blacktainfalcon7097
@blacktainfalcon7097 3 жыл бұрын
Thanks, could you maybe show how to do turn-based combat?
@beegdigit9811
@beegdigit9811 3 жыл бұрын
6:35 Where the delta time at Great video as always
@Challacade
@Challacade 3 жыл бұрын
Good question, the physics engine handles all dt-related calculations, so you don't have to worry about it at all!
@beegdigit9811
@beegdigit9811 3 жыл бұрын
​@@Challacade Looking at the source code it does seem like dt is passed to the world:update and that in turn passes it to all of it's children.
@Challacade
@Challacade 3 жыл бұрын
@@beegdigit9811 that's right. So since the world automatically takes care of all calculations, we don't have to worry about it whenever we're dealing with velocity
@comradechonky6328
@comradechonky6328 2 жыл бұрын
i don't have any problems but if set vx and vy as global variables(in the update function) instead of a local variable, the player keeps moving even after i stop pressing down the arrow keys. Can someone explain why this dosen't work
@RyanSinghI
@RyanSinghI 2 жыл бұрын
mostly everything works fine but when I reach a certain point on the map the player collider seems to move ahead of the character '
@koskenkorva123
@koskenkorva123 2 жыл бұрын
make sure your world:draw() is in the right place, above cam:detach()
@moonman2051
@moonman2051 3 жыл бұрын
Not considering my lack of understanding about the code, why do we need to assign the player to the collision box and not the opposite?
@hasagine3479
@hasagine3479 2 жыл бұрын
player would bypass collision if we did the opposite
@justinrudig6177
@justinrudig6177 Жыл бұрын
thanks now with that I created borders for my map
@DiegoTarragonaCovers
@DiegoTarragonaCovers 2 жыл бұрын
hi there, not sure if you could give me a hand with this, i'm trying to make a little roguelike, and using windfield for the collisions following this video i get movement as intended, but i'd want it to move only on 16px for every keypress, there's a way to move the colliders like that i spent the entire day trying with setLinearVelocity, applyForce and applyLinearImpulse
@KasperKenDev
@KasperKenDev 3 ай бұрын
This looks simpler than Godot, and I like the fact all your editing is in the text editor. I tried and failed to make godot work well with vim. And this is Lula so I’m intrigued. Do you feel you miss anything over godot?
@cryztalized2809
@cryztalized2809 Жыл бұрын
Ik you probs wont answer but im having issues with it sticking up to the left corner of the player, n ive tried a bunch of different things in trying to fix it but i just simply cant find the answer
@limu3749
@limu3749 3 жыл бұрын
I get an error after I implement this code 12:51 The error is libraries/windfield/Init.lua:745: Box2D assertion failed: area > b2_epsilon If I remove the code, its working well. I don't know what the cause of this error. please help, Thankyou
@growingmindset7
@growingmindset7 2 жыл бұрын
if u made a backup at ur game before doing this (i did this bc of this error) just create the 3rd backup and do on ur 2nd backup the tutorial, if it works, drop the main.lua in ur own game
@Niko75999
@Niko75999 2 жыл бұрын
SAME
@Niko75999
@Niko75999 2 жыл бұрын
.
@Niko75999
@Niko75999 2 жыл бұрын
.
@growingmindset7
@growingmindset7 2 жыл бұрын
@@Niko75999 y e s
@adamwhite9330
@adamwhite9330 2 жыл бұрын
It seems like needing a whole physics engine just to do collision checking is ridiculous overkill. Surely there's a better way? Games have had collision detection for a lot longer than they've had physics.
@itsaducklin
@itsaducklin 5 ай бұрын
you can definitely code your own aabb collision system, that's easy. but then theres making collisions for things that ARENT just rectangles and then you have a problem along with that, your same logic applies to things like: input, audio, or displaying graphics. and also, the whole physics engine isn't really performance intensive. we're in a day and age where games don't have to be that performant, especially 2d ones, as computers have progressed so much.
@Abiiiiiiiiiiiiii06
@Abiiiiiiiiiiiiii06 Жыл бұрын
How do you do so your Game doesn't go laggy? I have seen your Game cavern and It uses windfield colliders but It doesn't go laggy but mine does
@unedited12
@unedited12 2 жыл бұрын
Is it possible you could include a video or addon to a video that shows how to make your character go behind a sprited object when you walk behind it? I want to make it so my players can walk behind the trees and houses in my game that way they are more immersed!
@The_Codemaster144k
@The_Codemaster144k 2 жыл бұрын
draw whatever you want to walk behind, last and remove colliders on it. if that doesnt work then do the reverse
@unedited12
@unedited12 2 жыл бұрын
@@The_Codemaster144k What if it's also an item that you want to walk in front of later? I'm trying to make trees you can walk around from a over the top perspective
@The_Codemaster144k
@The_Codemaster144k 2 жыл бұрын
@@unedited12 well you can set a Boolean (true or false) value to set the rendering order. Other than that I really don’t know
@piago1457
@piago1457 Жыл бұрын
how do I make the player collider for a platformer? EDIT: also my player flips and comes out of the collide? can i also flip the collider along with the player sprite?
@Dada-zm2jb
@Dada-zm2jb 10 ай бұрын
Hello! love your videos! I would like to know how to turn this into a sidescroller. So I want to make something like this turned into a platformer with a jumping mechanic. However, when I turn gravity on, the character and the collider fall really slow and just doesn't feel natural. Thank you!!!
@pi_dev
@pi_dev 2 жыл бұрын
how do i draw something on a object layer
@eywrsome420
@eywrsome420 Жыл бұрын
hello I used the code and it didn't work my "local" is not purple as your code its blue. how can i fix my code. If you want I can share the code and error screen pls answer, thanks already
@Chipichipichapachapadubidubid
@Chipichipichapachapadubidubid 9 ай бұрын
it's okay. newer versions of vscode do that
@ATS-uy4vl
@ATS-uy4vl 3 жыл бұрын
AMAZING!!!!
@MrInfarct
@MrInfarct 2 жыл бұрын
when I do the set linear velocity my character moves by itself
@wh1pper457
@wh1pper457 Жыл бұрын
excellent guide! can I also ask why can't we use a code for the wall to not move like we used for the collider for player example: "wall.collider:setFixedRotation(true)"
@nicholaswatching
@nicholaswatching Жыл бұрын
Since the wall are static and cannot move, the positions of the walls can't move anyway, so it's not needed. For the player, it would rotate from the player movement I would guess.
@romannoodles5856
@romannoodles5856 Жыл бұрын
What if you have diagonal wall tiles?
@alivesurvive471
@alivesurvive471 Жыл бұрын
You can create diagonal collisions using polygon. If you just mean the images, you need several image assets to create realistic diagonal walls.
@Vectorez1
@Vectorez1 2 жыл бұрын
Can you change the collision color? and if so, how?
@im0genim0gen46
@im0genim0gen46 2 жыл бұрын
hey do this method work for polygon with more than 4 side?
@bratzchaki
@bratzchaki 2 жыл бұрын
Why did you put player.collider = world:newBSGRectangleCollider instead o player.collider = world:newRectangleCollider. The first one didn`t work to me.
@nonnullptrhuman504
@nonnullptrhuman504 2 жыл бұрын
world:newBSGRectangleCollider is the choice if you want polygon shape collider.
@dragondg6412
@dragondg6412 2 жыл бұрын
I was so close to the end but i had to give up every single sign told me to give up i only had this one and next but it was too much
@Robbit_
@Robbit_ 2 жыл бұрын
Would you happen to have a discord? I've followed all the steps but my walls turn completely white when I run the love2d project, if you know how to fix this, I'd love to know!
@Robbit_
@Robbit_ 2 жыл бұрын
@@stevones718 yeah, two of my layers in tiled where the same name, make sure you draw the right layers to the screen
@stinkyseastar3560
@stinkyseastar3560 Жыл бұрын
same, I have no idea what to do.
@chromeWarriorXIII
@chromeWarriorXIII 3 жыл бұрын
Is there a way to modify this to work with polygonal objects in Tiled, like slopes for example? Polygon Colliders require pairs of coordinates for the vertices so I'm not sure how to pass those to Windfield
@therevillsgames
@therevillsgames 3 жыл бұрын
Yep! I do something similar by creating a polygon object: platforms = {} if gameMap.layers["slopes"] then for i, obj in pairs(gameMap.layers["slopes"].objects) do local polygons = {} local polyObj = obj.polyline for vertNum = 1, #polyObj do local vert = polyObj[vertNum] table.insert(polygons, vert.x) table.insert(polygons, vert.y) end local p = self.world:newPolygonCollider(polygons) p:setType('static') p:setCollisionClass("Platform") table.insert(platforms, p) end end
@chromeWarriorXIII
@chromeWarriorXIII 3 жыл бұрын
@@therevillsgames Thanks but for some reason I'm getting an error on the line with #polyObj saying that the length is a nil value. Any idea what could be going wrong there?
@therevillsgames
@therevillsgames 3 жыл бұрын
@@chromeWarriorXIII In my example I have the polygons in the "slopes" object layer in Tiled, and in the export lua map it looks like this: { type = "objectgroup", draworder = "topdown", id = 7, name = "slopes", visible = true, opacity = 1, offsetx = 0, offsety = 0, parallaxx = 1, parallaxy = 1, properties = {}, objects = { { id = 123, name = "", type = "", shape = "polyline", x = 224, y = 576, width = 0, height = 0, rotation = 0, visible = true, polyline = { { x = 0, y = 0 }, { x = 128, y = -64 }, { x = 160, y = -64 }, { x = 224, y = -32 }, { x = 288, y = 0 }, { x = 0, y = 0 } }, properties = {} } } }, Check your map lua and the objects has a polyline table.
@chromeWarriorXIII
@chromeWarriorXIII 3 жыл бұрын
@@therevillsgames I also had my polygon layer named "slopes" but the shapes in my map lua are labeled as "polygon" not "polyline" and the table is polygon, not polyline
@therevillsgames
@therevillsgames 3 жыл бұрын
@@chromeWarriorXIII Strange, I added polyline only a week ago, but now when I add a new polygon in Tiled it does output the vertices in the polygon object :? Just update the code to read the polygon table :D Edit: ​ @meaningless [C]ode Ahhh - my "polygon" wasnt closed, so Tiled creates "polylines" table instead of "polygons".
@EMkrazy
@EMkrazy Жыл бұрын
Ps. Use only rectangle shape when making a collider in Tiled, if you use other shape like triangle, it won't work because in the code it says "newRectangleCollider" This tip is for newbee like me, if you know how to code with different shape of collider plss teach me🥺
@MirralisDias
@MirralisDias Жыл бұрын
I managed to get it working with Polylines and Polygons by looking at the structure of the testMap.lua file if gameMap.layers["Colliders"] then for i, obj in pairs(gameMap.layers["Colliders"].objects) do if obj["polyline"] then local lines = obj.polyline for j = 1, #lines do local point1 = lines[j] local point2 = lines[j + 1] if point2 then local line = world:newLineCollider(point1.x, point1.y, point2.x, point2.y) line:setType('static') end end elseif obj["polygon"] then local poly = world:newPolygonCollider(flatten(obj.polygon)) poly:setType('static') end end end
@EMkrazy
@EMkrazy Жыл бұрын
@@MirralisDias thanks bro
@wesleylima5723
@wesleylima5723 Жыл бұрын
Hey man, thank you so much for the video and explanation! I've found your channel and I am liking it fo much Could you help me a little? In my game the getX() and getY() methods return the center of the BSG collider. Do you know why this is happening? I want them to return the top left corner (as I suppose happens to you). Thanks!
@lauralegorreta4334
@lauralegorreta4334 2 жыл бұрын
9:46
@kushalshrivastav5469
@kushalshrivastav5469 2 жыл бұрын
I get error in code walls = {} if lvl.layers['Platform'] then for obj in pairs(lvl.layers['Platform'].objects) do local wall = wrld:newRectangleCollider(obj.x,obj.y,obj.width,obj.height) wall:setType('static') table.insert(walls,wall) end end that Error main.lua:28: bad argument #1 to 'pairs' (table expected, got nil) Traceback [love "callbacks.lua"]:228: in function 'handler' [C]: in function 'pairs' main.lua:28: in function 'load' [love "callbacks.lua"]:136: in function [C]: in function 'xpcall' [C]: in function 'xpcall'
@alessioturco953
@alessioturco953 2 жыл бұрын
Hi i did every thing and double checked if i misspelled something but i don't know why i says this. Does any one know ho to fix it? Error main.lua:30: bad argument #1 to 'pairs' (table expected, got nil) Traceback [love "callbacks.lua"]:228: in function 'handler' [C]: in function 'pairs' main.lua:30: in function 'load' [love "callbacks.lua"]:136: in function [C]: in function 'xpcall' [C]: in function 'xpcall'
@Challacade
@Challacade 2 жыл бұрын
Double check your line 30 in main.lua. It's saying that on line 30, you're attempting to do a pairs iteration on some table, but it's saying the table you passed in doesn't exist. So check the spelling and capitalization of what you put inside of the parentheses, and make sure that a table with that same name exists in your code
@alessioturco953
@alessioturco953 2 жыл бұрын
@@Challacade i've got as the layer name Walls but if i write the gameMap.layer["Walls"] then i would give me that error. here is what i wrote walls = {} if gameMap.layers["Walls"] then for i, obj in pairs(gameMap.layers["Walls"].object) do local wall = world:newRectangleCollider(obj.x, obj.y, obj.width, obj.height) wall:setType('static') table.insert(walls, wall) end end
@Challacade
@Challacade 2 жыл бұрын
@@alessioturco953 it should be pairs(gameMap.layers["Walls"].objects) Looks like it was a minor typo, where you have .object rather than .objects
@alessioturco953
@alessioturco953 2 жыл бұрын
@@Challacade sorry to bother again but the objects spelling did solve that error but now i have this one and i don't know what it means Error libraries/windfield/init.lua:745: Box2D assertion failed: area > b2_epsilon Traceback [love "callbacks.lua"]:228: in function 'handler' [C]: in function 'newFixture' libraries/windfield/init.lua:745: in function 'newRectangleCollider' main.lua:31: in function 'load' [love "callbacks.lua"]:136: in function [C]: in function 'xpcall' [C]: in function 'xpcall' again soory for bothering and thank for the help
@Challacade
@Challacade 2 жыл бұрын
@@alessioturco953 I think that error normally means there's some wall objects in your Walls object layer that have an area of 0, which is invalid. Try deleting your Walls object layer, and creating it again, placing in only a few walls at a time and testing it out
Sound Effects and Background Music in Love2D
6:03
Challacade
Рет қаралды 11 М.
It works #beatbox #tiktok
00:34
BeatboxJCOP
Рет қаралды 41 МЛН
Mom Hack for Cooking Solo with a Little One! 🍳👶
00:15
5-Minute Crafts HOUSE
Рет қаралды 23 МЛН
Making a Game in Lua with No Experience
5:52
Goodgis
Рет қаралды 363 М.
Level editing made easy with Automapping
34:36
AdamCYounis
Рет қаралды 258 М.
Easily create levels/maps for Love2D games (with Tiled)
7:56
Challacade
Рет қаралды 77 М.
Best Games from the Brackeys Game Jam 2024.2!
13:53
Brackeys
Рет қаралды 156 М.
2024's Biggest Indie Hit Was Made With... Love!   LÖVE 2D that is.
9:50
The HARDEST part of game development | Devlog
6:16
Challacade
Рет қаралды 90 М.
Making a Blacksmithing Game in 1 Week Using Love2D
5:11
SquidGod
Рет қаралды 25 М.
Intro to Physics in Love2D
13:23
Gabe Stein
Рет қаралды 2,2 М.
Love2D Tutorial | Simple Main Menu UI
17:24
SkyVaultGames
Рет қаралды 37 М.
Love2D | Shader Tutorial 1 | Introduction
13:42
SkyVaultGames
Рет қаралды 23 М.
It works #beatbox #tiktok
00:34
BeatboxJCOP
Рет қаралды 41 МЛН