Hey all,
I am trying to make a Breakout clone involving an entity system, however I can't figure out how to check for collision between the ball and the paddle. I currently have a require statement at the top of ball.lua and the lines of code that should cause the ball to bounce off of the paddle commented out. When I run this, it causes the ball to spawn at the correct location (x and y values passed in the ents.Create() function in main.lua) but the ball does not bounce off the paddle.
When the require statement and the lines are uncommented and run, the ball will only spawn in the top right corner of the screen and will collide with what looks like an invisible "paddle" at the position where the x and y coordinates are passed into ents.Create() which should be the spawn position of the ball.
How would I be able to get the x and y position of the paddle from the paddle.lua file to check for collisions in the ball.lua file without using global variables?
Using variables from another file?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Using variables from another file?
- Attachments
-
- breakout.love
- (3.26 KiB) Downloaded 83 times
- alberto_lara
- Party member
- Posts: 372
- Joined: Wed Oct 30, 2013 8:59 pm
Re: Using variables from another file?
You can access the bounds of the paddle just like this:
Then you need to detect a circle <> rectangle collision, here's a good approach:
https://gist.github.com/vonWolfehaus/5023015
Code: Select all
function love.load()
local sWidth = love.graphics.getWidth()
local sHeight = love.graphics.getHeight()
ents:Startup()
local ballEnt = ents.Create("ball", 100, 100)
local paddleEnt= ents.Create("paddle", sWidth/2 - 64, sHeight - 4)
print(paddleEnt.x, paddleEnt.y, paddleEnt.width, paddleEnt.height)
end
https://gist.github.com/vonWolfehaus/5023015
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], slime and 9 guests