I am using the love physics and I am getting this error
Error
main.lua:7: bad argument #2 to 'newFixture' (Shape expected, got nil)
Traceback
[love "callbacks.lua"]:228: in function 'handler'
[C]: in function 'newFixture'
main.lua:7: in function 'load'
[love "callbacks.lua"]:136: in function <[love "callbacks.lua"]:135>
[C]: in function 'xpcall'
[C]: in function 'xpcall'
although i am not sure what is wrong. My code looks like this
function love.load()
game = love.physics.newWorld(0, 0, true)
playerimage = love.graphics.newImage('assets/PLAYER.png')
player = love.physics.newBody(game, 500, 500, "dynamic")
player:setFixedRotation(true)
playerhitbox = love.physics.newCircleShape(95)
PlayerFixture = love.physics.newFixture(player, circle, 1)
end
if someone is able to help me, then please tell me what is wrong
Can someone help me with this error
-
- Prole
- Posts: 2
- Joined: Wed Dec 28, 2022 5:59 am
Re: Can someone help me with this error
I have no experience with physics. but according to the error message at line 7 in main.lua the second argument of newFixture() should be a type of Shape but it is nil.
newFixture() takes 3 arguments (body, shape, density)
A shape is a solid 2d geometrical objects which handle the mass and collision of a body.
For example ChainShape, CircleShape, RectangleShape.
You missing the shape, maybe you just spelled it wrong or you did not create one.
You can read more about it in the docs:
https://love2d.org/wiki/love.physics.newFixture
https://love2d.org/wiki/Shape
If it does not help, post your code or a small project we can try.
newFixture() takes 3 arguments (body, shape, density)
A shape is a solid 2d geometrical objects which handle the mass and collision of a body.
For example ChainShape, CircleShape, RectangleShape.
You missing the shape, maybe you just spelled it wrong or you did not create one.
You can read more about it in the docs:
https://love2d.org/wiki/love.physics.newFixture
https://love2d.org/wiki/Shape
If it does not help, post your code or a small project we can try.
Re: Can someone help me with this error
You define playerhitbox and then use circle, use either only playerhitbox or circle.
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Can someone help me with this error
yeah, doing the below line fixes it probably, since, you know, you named your circle shape playerhitbox...:
PlayerFixture = love.physics.newFixture(player, playerhitbox, 1)
PlayerFixture = love.physics.newFixture(player, playerhitbox, 1)
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
-
- Prole
- Posts: 2
- Joined: Wed Dec 28, 2022 5:59 am
Re: Can someone help me with this error
Thank you guys for the help!
I am no longer getting any errors
I am no longer getting any errors
Who is online
Users browsing this forum: No registered users and 1 guest