Hello LÖVEers,
I'm new in development with this awesome engine, but I've already have a lot of experience in Lua. (I'm coding Lua for GMod for almost three years.)
Well.. until now I really had not any problems in what I was doing, but then I wanted to do something with the physic functions. It worked pretty good so far, but now I have some really big problems with the collision.
To cut a long story short: I wanted to spawn bouncy balls on left click (which worked so far) and boxes with collision (which doesn't work at all).
The bouncy balls bounce when they are told to do so (when they hit the window rim), but the boxes are just.. weird.
In the picture below, the black boxes are drawn at the position where the bodies associated with the rectangular shapes should be, and the balls stuck where the "boxes" actually are.
In the next picture you'll see red and black boxes. The red boxes should mark where the shapes actually are (using "love.graphics.polygon( "line", v.shape:getPoints()" ) ), and the black boxes should mark where the bodies are. Curiously the shapes and bodies should have exact the same position, but they're always drawn in two different vectors.
Also, the game crashes if I'm trying to spawn a ball in the upper rim of the window.
I attached the game so you can try it yourself and maybe see what I did wrong in the code. Hopefully you can help me as soon as possible.
Thanks in advance.
PS: I aligned the window size and everything related to it to a 800x600 resolution, so everyone can try it out.
Problems with the physics functions
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Problems with the physics functions
- Attachments
-
- bouncy balls.love
- (1.85 KiB) Downloaded 151 times
- slime
- Solid Snayke
- Posts: 3162
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Problems with the physics functions
When you call
the x,y position of the shape is actually the offset from the body position. Change it to
and your shapes should be where you want. The same goes for the circle shapes.
EDIT: That might make the body be at the top left corner of the rectangle shape, I don't remember how box2d handles that.
Code: Select all
tbl.shape = love.physics.newRectangleShape( tbl.body, x, y, 100, 100 )
Code: Select all
tbl.shape = love.physics.newRectangleShape( tbl.body, 0, 0, 100, 100 )
EDIT: That might make the body be at the top left corner of the rectangle shape, I don't remember how box2d handles that.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Problems with the physics functions
Box2D uses center, as center of mass is the most important coordinate in physics.slime wrote:EDIT: That might make the body be at the top left corner of the rectangle shape, I don't remember how box2d handles that.
Re: Problems with the physics functions
Thank you very much. That part works now.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 4 guests