Hello their!
Now I'm new to programming i've been at it for like 3 days now.I've been making simple games like adventure games were you click buttons for answers like the walking dead ! I want to start more compacted things but for that i need to learn how to make collision or a hitbox. I've looked for help but all were badly explained and i didn't get the grasp on it. So if anyone has good easy tutorials that can give that will be awesome! Also i could use a library if i have to but people say i should get the grasp of making collision my self.
thanks for the help
-SSheep_
Collison- yes i know more collision help
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Ranguna259
- Party member
- Posts: 911
- Joined: Tue Jun 18, 2013 10:58 pm
- Location: I'm right next to you
Re: Collison- yes i know more collision help
I usualy recomend to look into [wiki]love.physics[/wiki], it's not as hard as the page says it is but people here tend to say not use it as it's overpowerd if you are thinking on doing simple things but hey I've been using it for a long time and I had not problems with it.
Here's a sample "hitbox", more like a button:
EDIT: Also the thing about collision is not how you detect if two bodies are colliding, it's the response you get after they collide, that's the hard part because you never know if the body is hitting from the right or from the left or from anywhere, in this case all you can do is to guess but by guessing you'll probably get lots of bugs like unwanted body teleportations. Best of luck
EDIT2: Here's circle to point collision detection
The dist function:
The collision:
Circle to circle collision detection:
Rectangle to rectangle:
All those are the easy ones then it start to get complicated when you collide special convex shapes.
Here's a sample "hitbox", more like a button:
Code: Select all
if x > box.x and x < box.x+box.width and y > box.y and y < box.y+box.height then
-- the (x,y) coordinates are inside the box
end
EDIT2: Here's circle to point collision detection
The dist function:
Code: Select all
function dist(x1,y1,x2,y2)
return (math.sqrt((x1-x2)^2+(y1-y2)^2)))
end
Code: Select all
if dist(circle.x,circle.y,x,y) <= circle.radius then
-- point is inside the circle
end
Code: Select all
if dist(circle1.x,circle1.y,circle2.x,circle2.y) < cirlce1.radius+circle2.radius then
-- the two circle are colliding
end
Code: Select all
if obj1.x+obj1.width < obj2.x or obj1.x > obj2.x+obj2.width or obj1.y+obj1.height < obj2.y or obj1.y > obj2.y+obj2.height then
--the two rectangles are colliding
end
Re: Collison- yes i know more collision help
Hi thanks for the replay very easy to understand but i got a error when trying to use it
heres my code
and my error is
syntax error: main.lua:20 '=' expected near 'love'
i tried to see if i can fix it but i can't find the error
heres my code
Code: Select all
require "player"
function love.load()
love.graphics.setBackgroundColor(255,255,255)
gameState = "playing"
boxX = 100
boxY = 100
boxWidth = 32
boxHeight = 32
end
function love.update(dt)
if gameState == "playing" then
playerMove(dt)
if player.x > boxX and player.x < boxX + boxWidth and player.y > boxY and player.y < boxY + boxHeight then
love.graphics.setColor(255,20,0)
love.graphics.print("test", 200,200)
end
end
end
function love.draw()
if gameState == "playing" then
playerDraw()
love.graphics.setColor(255,20,0)
love.graphics.rectangle("fill", boxX, boxY, boxWidth, boxHeight)
end
end
syntax error: main.lua:20 '=' expected near 'love'
i tried to see if i can fix it but i can't find the error
- Ranguna259
- Party member
- Posts: 911
- Joined: Tue Jun 18, 2013 10:58 pm
- Location: I'm right next to you
Re: Collison- yes i know more collision help
Hmmm.. This looks really wierd, everything looks fine.
Could you post the .love ?
Could you post the .love ?
Re: Collison- yes i know more collision help
I acutely fixed it i just copied the code and past it again and it worked lolRanguna259 wrote:Hmmm.. This looks really wierd, everything looks fine.
Could you post the .love ?
thanks for the help
Who is online
Users browsing this forum: Bing [Bot], Semrush [Bot] and 4 guests