Тёмный

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

Challacade
Подписаться 69 тыс.
Просмотров 31 тыс.
50% 1

This video goes through the process of putting a hitbox on your player character, which forces them to stop when walking into walls. Additionally, I discuss the process of automatically generating these walls based off of a Tiled map.
Here is the sample project that I use during this video: github.com/kyleschaub/snippet...
Link to windfield:
github.com/a327ex/windfield
0:00 Introduction
0:13 Getting windfield
1:13 Creating the World
2:07 Player Collider
4:54 Collider Movement
7:26 Walls
8:59 Generate walls from Tiled
13:35 Outro
#gamedev

Игры

Опубликовано:

 

22 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 97   
@YoshimiGames
@YoshimiGames 2 года назад
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 4 месяца назад
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 9 месяцев назад
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.
@pokeman5796
@pokeman5796 2 года назад
Great video🔥thank you for the upload.
@andre.gabriel
@andre.gabriel 2 года назад
Great video thanks for sharing your knowledge. 😀
@BrandonS-lk2qc
@BrandonS-lk2qc 2 года назад
Thank you for doing this!
@shamsparvezarka1860
@shamsparvezarka1860 Год назад
This video is a lifesaver
@big_swivel
@big_swivel 2 года назад
How would I approach checking if the player collides with a certain collider?
@blacktainfalcon7097
@blacktainfalcon7097 2 года назад
Thanks, could you maybe show how to do turn-based combat?
@MirralisDias
@MirralisDias 8 месяцев назад
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?
@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
@comradechonky6328
@comradechonky6328 Год назад
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
@Dada-zm2jb
@Dada-zm2jb 5 месяцев назад
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!!!
@basimo5792
@basimo5792 Год назад
Can you change the collision color? and if so, how?
@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?
@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?
@jolteon_03
@jolteon_03 8 месяцев назад
How can I add the wall collisons using bump instead? Windfield is very laggy
@pi_dev
@pi_dev 2 года назад
how do i draw something on a object layer
@im0genim0gen46
@im0genim0gen46 2 года назад
hey do this method work for polygon with more than 4 side?
@idoblenderstuffs
@idoblenderstuffs Год назад
pleeeease continue this tutorial series
@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
@jolteon_03
@jolteon_03 8 месяцев назад
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
@ATS-uy4vl
@ATS-uy4vl 2 года назад
AMAZING!!!!
@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
@moonman2051
@moonman2051 2 года назад
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
@MrInfarct
@MrInfarct 2 года назад
when I do the set linear velocity my character moves by itself
@_gamerlama5382
@_gamerlama5382 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 Год назад
make sure your world:draw() is in the right place, above cam:detach()
@justinrudig6177
@justinrudig6177 Год назад
thanks now with that I created borders for my map
@wh1pper457
@wh1pper457 10 месяцев назад
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 8 месяцев назад
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.
@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
@Ranakade
@Ranakade 8 часов назад
Do you have any tutorials programming collision vanilla?
@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
@Kalebjosewitz
@Kalebjosewitz 2 года назад
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
@romannoodles5856
@romannoodles5856 9 месяцев назад
What if you have diagonal wall tiles?
@alivesurvive471
@alivesurvive471 9 месяцев назад
You can create diagonal collisions using polygon. If you just mean the images, you need several image assets to create realistic diagonal walls.
@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.
@beegdigit9811
@beegdigit9811 2 года назад
6:35 Where the delta time at Great video as always
@Challacade
@Challacade 2 года назад
Good question, the physics engine handles all dt-related calculations, so you don't have to worry about it at all!
@beegdigit9811
@beegdigit9811 2 года назад
​@@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 2 года назад
@@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
@beatrz3
@beatrz3 Год назад
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 Год назад
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 Год назад
@@Challacade ty very much it worked now:)
@gamerule36
@gamerule36 7 месяцев назад
thanks so much this also fixed my problem @@beatrz3
@eywrsome420
@eywrsome420 8 месяцев назад
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 4 месяца назад
it's okay. newer versions of vscode do that
@chromeWarriorXIII
@chromeWarriorXIII 2 года назад
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 2 года назад
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 2 года назад
@@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 2 года назад
@@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 2 года назад
@@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 2 года назад
@@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".
@brunogaio6210
@brunogaio6210 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.
@limu3749
@limu3749 2 года назад
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
@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!
@EMkrazy
@EMkrazy 9 месяцев назад
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 8 месяцев назад
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 8 месяцев назад
@@MirralisDias thanks bro
@adamwhite9330
@adamwhite9330 Год назад
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.
@SuitedGhost
@SuitedGhost 8 дней назад
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.
@lauralegorreta4334
@lauralegorreta4334 Год назад
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'
@trouble6043
@trouble6043 8 месяцев назад
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 4 месяца назад
SAME!!
@tarunthakur6091
@tarunthakur6091 2 месяца назад
me too
@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
Просмотров 10 тыс.
Копия iPhone с WildBerries
01:00
Просмотров 834 тыс.
The HARDEST part of game development | Devlog
6:16
Просмотров 31 тыс.
I Optimised My Game Engine Up To 12000 FPS
11:58
Просмотров 595 тыс.
How to ACTUALLY get into Gamedev
14:01
Просмотров 702 тыс.
Collision Detection (An Overview) (UPDATED!)
7:27
Просмотров 34 тыс.
Collisions and Vectors | Recreating Zelda
8:18
Просмотров 22 тыс.
Dear Game Developers, Stop Messing This Up!
22:19
Просмотров 695 тыс.
ИСТОРИЯ ИГРОВЫХ МЕМОВ
25:10
Просмотров 112 тыс.