How to set a collision for the wall / player
4 replies



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
17.09.23 09:49:16 pm


and this problem is so strange for me



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

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

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
Code:
1
2
3
4
5
6
7
8
9
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
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

Code:
1
2
2
local vx = 0
local vy = 0
local vy = 0

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

Code:
1
player.collider:setLinearVelocity(vx , vy)

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

Code:
1
world:draw()

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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'
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'


i hope anyone to solve it

1. Please check the obj. values (negative height/width or nil or similiar???)
2. Change
Into
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?
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
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
Code:
1
player.collider = world:newBSGRectangleCollider(400 , 250 , 50 , 100 , 10)
Into
Code:
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?
Share time limited free games here


1. Please check the obj. values (negative height/width or nil or similiar???)
2. Change
Into
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?
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
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
Code:
1
player.collider = world:newBSGRectangleCollider(400 , 250 , 50 , 100 , 10)
Into
Code:
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?

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


the error of line 745 is : Box2D assertion failed: area > b2_epsilon
in function 'newRectangleCollider'

the error :
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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'
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'



(
Code:
)1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
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

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

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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'
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'


You are supposed to print the values to look through them yourself ...
When you have negative areas then there are no wonders you get an error like "Box2D assertion failed: area > b2_epsilon"
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?
With this mindset, you are better off asking ChatGPT!
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'
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
Share time limited free games here


You are supposed to print the values to look through them yourself ...
When you have negative areas then there are no wonders you get an error like "Box2D assertion failed: area > b2_epsilon"
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?
With this mindset, you are better off asking ChatGPT!
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'
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!


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

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

Code:
1
2
3
4
5
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'
[C]: in function 'newFixture'
[love "callbacks.lua"]:136: in function <[love "callbacks.lua"]:135>
[C]: in function 'xpcall'
[C]: in function 'xpcall'


Code:
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
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
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





