Forum

> > Off Topic > How to set a collision for the wall / player
Forums overviewOff Topic overviewLog in to reply

English How to set a collision for the wall / player

4 replies
To the start Previous 1 Next To the start

Poll Poll

how to solve this problem ?

Only registered users are allowed to vote
you missed something in tiled
0.00% (0)
you did a wrong code
100.00% (2)
you have missed files from windfield
0.00% (0)
you included wrong paths
0.00% (0)
2 votes cast

old Poll How to set a collision for the wall / player

blurr
User Off Offline

Quote
• Hello , guys

• this day after i fixed the embed tile now i had another problem
and this problem is so strange for me

• i couldnt solve it

• the first thing that i was watching a vid for how to make a collision for the wall / player i put these codes :

1
2
wf = require 'windfield'
  world = wf.newWorld(0 ,0)

• this code for including the windfield folder for the love2d file after it i put this code for making a collider


1
2
player.collider = world:newBSGRectangleCollider(400 , 250 , 50 , 100 , 10)
  player.collider:setFixedRotation(true)

• then i put this code i think it is for loading the collision for the walls / player
and this code who gave me an error after i run it but i will give you the other codes to understand the problem well


1
2
3
4
5
6
7
8
9
walls = {}
    if map.layers['walls'] then
      for i, obj in pairs(map.layers['walls'].objects) do
        local wall = world:newRectangleCollider(obj.x , obj.y , obj.width , obj.height)
        wall:setType('static')
        table.insert(walls , wall)
      end
    end
end


• then i put this code i think it is for setting the simple collision at the position ( 0, 0)

1
2
local vx = 0 
  local vy = 0


• then i put to the row of the player movement code these codes :

1
2
3
4
vx = player.speed
vx = player.speed * -1
vy = player.speed
vy = player.speed * -1



• then i put this code for setting a velocity to the player collider

1
player.collider:setLinearVelocity(vx , vy)


• then i added this code for updating the world and for setting the position x / position y for the player collider


1
2
3
world:update(dt)
   player.x = player.collider:getX()
   player.y = player.collider:getY()


• then i put this code at the end to draw the world

1
world:draw()

• and at the end of all of this i got this error and i really dont know what i should modify to make my love2d project work

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Error

windfield/init.lua:745: Box2D assertion failed: area > b2_epsilon


Traceback

[love "callbacks.lua"]:228: in function 'handler'
[C]: in function 'newFixture'
windfield/init.lua:745: in function 'newRectangleCollider'
main.lua:40: in function 'load'
[love "callbacks.lua"]:136: in function <[love "callbacks.lua"]:135>
[C]: in function 'xpcall'
[C]: in function 'xpcall'


illegal note : this code isnt compeleted it is just for loading the collisons to the wall / player

illegal note : while i was watching the vid i went to tiled and i added an object and i called it walls then i went to ground layer to draw the wall then i went to walls object to select the wall by insert rectangle tool in tiled then after i selected the rectangle wall by insert rectangle tool i exported the file as lua and i already have the code that loads the map then i got the error ^^^^


i hope anyone to solve it

old Re: How to set a collision for the wall / player

Bowlinghead
User Off Offline

Quote
1. Please check the obj. values (negative height/width or nil or similiar???)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
walls = {}
    if map.layers['walls'] then
      for i, obj in pairs(map.layers['walls'].objects) do
	--[[
		PLEASE ADD HERE:
	]]--
	print(obj.x)
	print(obj.y)
	print(obj.width)
	print(obj.height)
        local wall = world:newRectangleCollider(obj.x , obj.y , obj.width , obj.height)
        wall:setType('static')
        table.insert(walls , wall)
      end
    end
end


2. Change
1
player.collider = world:newBSGRectangleCollider(400 , 250 , 50 , 100 , 10)
Into
1
player.collider = world:newBSGRectangleCollider(400 , 250 , 50 , 100 , 0)
for testing purpose?

3. Which line does trigger the error? What line do you have to comment out to make the error dissappear/make another error visible?

4. Did you google yet?

old Re: How to set a collision for the wall / player

blurr
User Off Offline

Quote
user Bowlinghead has written
1. Please check the obj. values (negative height/width or nil or similiar???)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
walls = {}
    if map.layers['walls'] then
      for i, obj in pairs(map.layers['walls'].objects) do
	--[[
		PLEASE ADD HERE:
	]]--
	print(obj.x)
	print(obj.y)
	print(obj.width)
	print(obj.height)
        local wall = world:newRectangleCollider(obj.x , obj.y , obj.width , obj.height)
        wall:setType('static')
        table.insert(walls , wall)
      end
    end
end


2. Change
1
player.collider = world:newBSGRectangleCollider(400 , 250 , 50 , 100 , 10)
Into
1
player.collider = world:newBSGRectangleCollider(400 , 250 , 50 , 100 , 0)
for testing purpose?

3. Which line does trigger the error? What line do you have to comment out to make the error dissappear/make another error visible?

4. Did you google yet?




• answer 1. i checked and this is the code that i negatived the height/width in it :

1
local wall = world:newRectangleCollider(obj.x , obj.y , obj.width , obj.height)

• answer 2. i changed it but i have another ask i should print the obj x/y and print obj width/height before loading the object ? + if that code is right (the code you gave me) then how the code i got from the vid is wrong

• answer 3. it is in line 745 in init.lua < windfield library
the error of line 745 is : Box2D assertion failed: area > b2_epsilon
in function 'newRectangleCollider'

• you can see too another errors in other lines i already put it in the thread topic but i will show you it again

the error :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Error

windfield/init.lua:745: Box2D assertion failed: area > b2_epsilon


Traceback

[love "callbacks.lua"]:228: in function 'handler'
[C]: in function 'newFixture'
windfield/init.lua:745: in function 'newRectangleCollider'
main.lua:40: in function 'load'
[love "callbacks.lua"]:136: in function <[love "callbacks.lua"]:135>
[C]: in function 'xpcall'
[C]: in function 'xpcall'


• answer 4. i already did for 2 hours by searching about the problem

• quistion 1. can you explain what i did wrong and how you solved it if the code you gave to me worked and also if it didnt work explain what is the wrong and how to solve it , please


• now i tryied the code you gave me

(
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
walls = {}
    if map.layers['walls'] then
      for i, obj in pairs(map.layers['walls'].objects) do
     --[[
          PLEASE ADD HERE:
     ]]--
     print(obj.x)
     print(obj.y)
     print(obj.width)
     print(obj.height)
        local wall = world:newRectangleCollider(obj.x , obj.y , obj.width , obj.height)
        wall:setType('static')
        table.insert(walls , wall)
      end
    end
end
)


• i also put this code you gave me


(
1
player.collider = world:newBSGRectangleCollider(400 , 250 , 50 , 100 , 0)
)

• and when i saved and run i got this error :


1
2
3
4
5
6
7
8
9
10
11
12
13
14
Error

windfield/init.lua:745: Box2D assertion failed: area > b2_epsilon


Traceback

[love "callbacks.lua"]:228: in function 'handler'
[C]: in function 'newFixture'
windfield/init.lua:745: in function 'newRectangleCollider'
main.lua:47: in function 'load'
[love "callbacks.lua"]:136: in function <[love "callbacks.lua"]:135>
[C]: in function 'xpcall'
[C]: in function 'xpcall'


• idk if there is different between the first error i got and the second error but i hope you to solve it

old Re: How to set a collision for the wall / player

Bowlinghead
User Off Offline

Quote
You are supposed to print the values to look through them yourself ...
Quote
answer 1. i checked and this is the code that i negatived the height/width in it :

When you have negative areas then there are no wonders you get an error like "Box2D assertion failed: area > b2_epsilon"


Quote
you can see too another errors in other lines i already put it in the thread topic but i will show you it again

the error :
Errorwindfield/init.lua:745: Box2D assertion failed: area > b2_epsilon


Traceback

[love "callbacks.lua"]:228: in function 'handler'
[C]: in function 'newFixture'
windfield/init.lua:745: in function 'newRectangleCollider'
main.lua:40: in function 'load'
[love "callbacks.lua"]:136: in function <[love "callbacks.lua"]:135>
[C]: in function 'xpcall'
[C]: in function 'xpcall'

Yeah no shit sherlock: BUT how am I supposed to read any information out of this when I dont know where main.lua line 40 is for example?


Quote
idk if there is different between the first error i got and the second error but i hope you to solve it

With this mindset, you are better off asking ChatGPT!
edited 1×, last 18.09.23 06:24:49 pm

old Re: How to set a collision for the wall / player

blurr
User Off Offline

Quote
user Bowlinghead has written
You are supposed to print the values to look through them yourself ...
Quote
answer 1. i checked and this is the code that i negatived the height/width in it :

When you have negative areas then there are no wonders you get an error like "Box2D assertion failed: area > b2_epsilon"


Quote
you can see too another errors in other lines i already put it in the thread topic but i will show you it again

the error :
Errorwindfield/init.lua:745: Box2D assertion failed: area > b2_epsilon


Traceback

[love "callbacks.lua"]:228: in function 'handler'
[C]: in function 'newFixture'
windfield/init.lua:745: in function 'newRectangleCollider'
main.lua:40: in function 'load'
[love "callbacks.lua"]:136: in function <[love "callbacks.lua"]:135>
[C]: in function 'xpcall'
[C]: in function 'xpcall'

Yeah no shit sherlock: BUT how am I supposed to read any information out of this when I dont know where main.lua line 40 is for example?


Quote
idk if there is different between the first error i got and the second error but i hope you to solve it

With this mindset, you are better off asking ChatGPT!



• sorry i forgot to give you the code in the line that has the error i will give you the code from every line that error said

• line 47 error in main.lua (the main file for making the game) :


1
local wall = world:newRectangleCollider(obj.x , obj.y , obj.width , obj.height)


• now i will give you the error/wrong code in init.lua < windfield


1
fixture = love.physics.newFixture(self.body, shape)

• i tryied to search about callbacks.lua in the folder of the love2d project file but i couldnt see it in any folder but i will give you the error you may understand it



1
2
3
4
5
[love "callbacks.lua"]:228: in function 'handler'
[C]: in function 'newFixture'
[love "callbacks.lua"]:136: in function <[love "callbacks.lua"]:135>
[C]: in function 'xpcall'
[C]: in function 'xpcall'


• i really wanted to give you the whole informations you wanted but i really searched well tell me if you want many/more informations for fixing the problem

• now i will give you the whole code of my project to fix it well

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
function love.load()

  wf = require 'windfield'
  world = wf.newWorld(0 ,0)

  camera = require 'camera'
  cam = camera()

  anim8 = require 'lib/anim8'
  love.graphics.setDefaultFilter("nearest","nearest")

  sti = require 'lib/sti'
  map = sti('map.lua')

  player ={}
  player.collider = world:newBSGRectangleCollider(400 , 250 , 50 , 100 , 0)
  player.collider:setFixedRotation(true)
  player.x = 400
  player.y = 300
  player.speed = 300 
  player.sprite = love.graphics.newImage('player1.png')
  player.spritesheet = love.graphics.newImage('player-sheet.png')
  player.grid = anim8.newGrid(12,18,player.spritesheet:getWidth(),player.spritesheet:getHeight())
   
      
    player.animations = {}
    player.animations.down = anim8.newAnimation(player.grid('1-4',1),0.2) 
    player.animations.left = anim8.newAnimation(player.grid('1-4',2),0.2)
    player.animations.right = anim8.newAnimation(player.grid('1-4',3),0.2)
    player.animations.up = anim8.newAnimation(player.grid('1-4',4),0.2)

    player.anim = player.animations.left

    background = love.graphics.newImage('platform1.png')


    walls = {}
    if map.layers['walls'] then
      for i, obj in pairs(map.layers['walls'].objects) do
     --[[
          PLEASE ADD HERE:
     ]]--
     print(obj.x)
     print(obj.y)
     print(obj.width)
     print(obj.height)
        local wall = world:newRectangleCollider(obj.x , obj.y , obj.width , obj.height)
        wall:setType('static')
        table.insert(walls , wall)
      end
    end
end

function love.update(dt)
  local ismoving = false

  local vx = 0 
  local vy = 0


  if love.keyboard.isDown("right") then
   vx = player.speed
   player.anim = player.animations.right
   ismoving = true
  end

  if love.keyboard.isDown("left") then
    vx = player.speed * -1
    player.anim = player.animations.left
    ismoving = true
   end

   if love.keyboard.isDown("down") then
    vy = player.speed
    player.anim = player.animations.down
    ismoving = true
   end

   if love.keyboard.isDown("up") then
    vy = player.speed * -1
    player.anim = player.animations.up
    ismoving = true
   end

   player.collider:setLinearVelocity(vx , vy)

   if ismoving == false then 
  player.anim:gotoFrame(2)
   end

   world:update(dt)
   player.x = player.collider:getX()
   player.y = player.collider:getY()

   player.anim:update(dt)

   cam:lookAt(player.x,player.y)

   local w = love.graphics.getWidth()
   local h = love.graphics.getHeight()
   local mapw = map.width * map.tilewidth
   local maph = map.height * map.tileheight

   if cam.x <  w/2 then
    cam.x =  w/2

   end

   if cam.y < h/2 then
    cam.y =  h/2
    
   end

   if cam.x > ( mapw  - w/2) then
    cam.x = (mapw - w/2)

   end

   if cam.y > ( maph - h/2) then
    cam.y = ( maph - h/2 )
    
   end

end

function love.draw()
  cam:attach()
  map:drawLayer(map.layers["ground"])
  map:drawLayer(map.layers["tree"])
player.anim:draw(player.spritesheet,player.x,player.y,nil,6,nil,6,9)
 world:draw() 
cam:detach()
end


• this is the whole code of my love2d project i hope you to solve it if you need more something to fix the problem tell me
To the start Previous 1 Next To the start
Log in to replyOff Topic overviewForums overview