Trouble with my collision detector/resolver

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
ZBoyer1000
Prole
Posts: 39
Joined: Sat Nov 28, 2015 10:13 am

Trouble with my collision detector/resolver

Post by ZBoyer1000 »

https://www.mediafire.com/?eqh1pp3phac22cj

I decided to try to work on making a custom collision detector/resolver and I ran into a problem that I can not fix without help.
Can anyone please help? I have been trying to fix it for hours. :cry:
User avatar
pgimeno
Party member
Posts: 3548
Joined: Sun Oct 18, 2015 2:58 pm

Re: Trouble with my collision detector/resolver

Post by pgimeno »

Please help us help you by:
- Attaching the file to the post rather than using file sharing sites.
- Stating what the problem is, what you expect and what is happening instead. Note that only you know how it's supposed to work, so if you don't tell us, we can't distinguish normal from buggy behaviour.
- Specifying what exact area of the code you need help with. You can't expect us to read your full code just to do the debugging for you. Please understand that it's more likely for you to get help if you're more specific, since analysing someone else's code in full may take quite some time that not many have or are willing to spend.

In short, please make it as easy as possible for people to help you.
ZBoyer1000
Prole
Posts: 39
Joined: Sat Nov 28, 2015 10:13 am

Re: Trouble with my collision detector/resolver

Post by ZBoyer1000 »

Problem: Collision Detection/Resolver

Function: tile_collisions(id)

Code that is causing the reoccurring problem:
local y_statements = entity_n[3] - block_tile[3] < 95 and entity_n[3] - block_tile[3] > -95
local x_statements = entity_n[2] - block_tile[2] < 52 and entity_n[2] - block_tile[2] > -52
--Collision resolving
if y_statements and x_statements == false then
if entity_n[3] + 95 < block_tile[3] then
entity_n[3] = block_tile[3] + 95
elseif entity_n[3] < block_tile[3] + 95 then
entity_n[3] = block_tile[3] - 95
end
elseif x_statements and y_statements == false then
if entity_n[2] < block_tile[2] + 50 then
entity_n[2] = block_tile[2] + 50
elseif entity_n[2] + 50 > block_tile[2] then
entity_n[2] = block_tile[2] - 50
end
end

Note: entity_n[2] and block_tile[2] are the x coordinates of the objects
entity_n[3] and block_tile[3] are the y coordinates of the objects
Mediafire is reliable for keeping files available for a long time. :P
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Trouble with my collision detector/resolver

Post by s-ol »

Mediafire is reliable, but also a 3rd-party site which we don't need to rely on. If you upload it right here on the forums, it will always be available when someone reads it here, and if it's offline the post will be offline with it.

If you post code, please use code tags so it is readable.

You still haven't said what the problem is. Please tell us what you expect/want to happen, and what happens instead. Are there error messages?

Also, there is a red notice at the top telling you to read the things to do before making a help thread:

Image

you basically broke all the rules that apply. Noone is going to be super upset you did and we are still going to help you some way or another, but it doesn't help you get an answer or us to be friendly and helpful.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
ZBoyer1000
Prole
Posts: 39
Joined: Sat Nov 28, 2015 10:13 am

Re: Trouble with my collision detector/resolver

Post by ZBoyer1000 »

Alright. Fine. I will just try to do this myself.
User avatar
airstruck
Party member
Posts: 650
Joined: Thu Jun 04, 2015 7:11 pm
Location: Not being time thief.

Re: Trouble with my collision detector/resolver

Post by airstruck »

ZBoyer1000 wrote:Alright. Fine. I will just try to do this myself.
I'd suggest eliminating magic numbers and using good variable names as a first step. This should make your code easier to reason about, and when you can reason about it more easily you should be able to find problems more easily.
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Trouble with my collision detector/resolver

Post by s-ol »

ZBoyer1000 wrote:Alright. Fine. I will just try to do this myself.
It's not that I don't want to help you, it's that you make it hard for me to do so. Yes, I could've taken the time to download, unpack and debug your code, but if you took the time to tell us the actual issue instead you would have a lot more people willing to help you because of the lower effort required to understand your problem alone.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 160 guests