Hello everyone,
well I'm creating a RPG game in Love2D 0.9.2 but I have no idea how to create a collision in the game, for example: When you touch the wall and do not pass it to the wall. If you help me I am very grateful!
if you want to modify my game adding the collision and let the file for me to download.
How i put Collision in my Game?
-
- Prole
- Posts: 12
- Joined: Fri Jul 03, 2015 8:54 pm
How i put Collision in my Game?
- Attachments
-
- green-world0.1.love
- (4.95 KiB) Downloaded 138 times
-
- Prole
- Posts: 21
- Joined: Wed Apr 15, 2015 10:51 pm
Re: How i put Collision in my Game?
First off, this should go in support and development, but that's beside the point. I would recommend using either the bump library, which I haven't used but have heard good things about, or using AABB collision detection. AABB collision detection is fairly simple for rectangles and circles. For rectangles, you need the location of the X and Y of the top left and bottom right of both rectangles. Here is the code behind it
I think this should work, but I might have messed up XD
Anyone feel free to correct me
Here is a picture explaining where the variables are(the rectangles can be any size)
Good Luck
Code: Select all
local RightCollision = false
local LeftCollision = false
local DownCollision = false
local UpCollision = false
local Box1X = Number--X of top left of box #1
local Box1Y = Number--Y of top left of box #1
local Box1XX = Number--X of bottom right of box#1
local Box1YY = Number--Y of bottom right of box #1
local Box2X = Number--X of top left of box #2
local Box2Y = Number--Y or top left of box #2
local Box2XX = Number--X of bottom right corner of box #2
local Box2YY = Number--Y of bottom right corner of box #2
if Box1XX>=Box2X and Box1Y<=Box2YY and Box1YY>Box2Y then
collisionRight = false
end
if Box1X<=Box2XX and Box1Y<=Box2YY and Box1YY>Box2Y then
collisionLeft = false
end
if Box1YY>=Box2Y and Box1XX>Box2X and Box1X<Box2XX then
collisionDown = true
end
if Box1Y<=Box2YY and Box1XX>Box2X and Box1X<Box2XX then
collisionUp = true
end
Anyone feel free to correct me
Here is a picture explaining where the variables are(the rectangles can be any size)
Good Luck
-
- Prole
- Posts: 12
- Joined: Fri Jul 03, 2015 8:54 pm
Re: How i put Collision in my Game?
I do not understand !,
you could pass the adapted code in my project?
thanks.
you could pass the adapted code in my project?
thanks.
Re: How i put Collision in my Game?
No one will want to sit and code the game for you...CloudyYard wrote:I do not understand !,
you could pass the adapted code in my project?
thanks.
You got an excellent explanation from Cookie10monster, if you don't want to manually add your own AABB collision then check out a library as mentioned or even the Löve built in physics (based on box2d).
If you do not understand, then you will just have to learn. Maybe some basic geometry?
-
- Prole
- Posts: 12
- Joined: Fri Jul 03, 2015 8:54 pm
Re: How i put Collision in my Game?
I am a beginner in Love2D, and I am a Brazilian ....
I'm using google translate and not get it right.
I'm using google translate and not get it right.
- Positive07
- Party member
- Posts: 1014
- Joined: Sun Aug 12, 2012 4:34 pm
- Location: Argentina
Re: How i put Collision in my Game?
That answer is super complete, if you still dont get it, Google is your friend, search AABB collisions it is rather simple stuff
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
Re: How i put Collision in my Game?
Löve is more of a game framework than a game engine. It does not come with "batteries included" so to speak. Löve is designed to allow the game developer maximum freedom, by not forcing the developer to make their game in a specific way. For a beginner, it might be easier to use a game engine with more functionality built-in and easier to use.
My game called Hat Cat and the Obvious Crimes Against the Fundamental Laws of Physics is out now!
Re: How i put Collision in my Game?
with few seconds on google, i've searched something for you:
http://www.dcc.ufrj.br/~abdalla/tut_arq/colisao.htm -> AABB Algorithm is the 3rd. (in portuguese)
http://www.gamefromscratch.com/post/201 ... g-box.aspx
https://developer.mozilla.org/en-US/doc ... _detection
If you don't get it, maybe you need to learn some math for game development( basically it's just geometry):
http://www.fabricadejogos.net/posts/tut ... ordenadas/ (in portuguese)
This blog has a serie about math for game development.
Btw, im brazilian too..
Good luck with your game
http://www.dcc.ufrj.br/~abdalla/tut_arq/colisao.htm -> AABB Algorithm is the 3rd. (in portuguese)
http://www.gamefromscratch.com/post/201 ... g-box.aspx
https://developer.mozilla.org/en-US/doc ... _detection
If you don't get it, maybe you need to learn some math for game development( basically it's just geometry):
http://www.fabricadejogos.net/posts/tut ... ordenadas/ (in portuguese)
This blog has a serie about math for game development.
Btw, im brazilian too..
Good luck with your game
Hey dude
Do you want to protect earth from an apocalypse ? Me too o/
Check my new game here: viewtopic.php?f=5&t=81001
Do you want to protect earth from an apocalypse ? Me too o/
Check my new game here: viewtopic.php?f=5&t=81001
Who is online
Users browsing this forum: Ahrefs [Bot] and 2 guests