Author Topic: problems  (Read 9270 times)

0 Members and 1 Guest are viewing this topic.

Offline feerik

  • LV2 Member (Next: 40)
  • **
  • Posts: 23
  • Rating: +0/-0
    • View Profile
problems
« on: December 08, 2010, 07:08:50 pm »
            this language is new to me, but im starting to understand but could anyone help me with some weird thing.

            the problem is:
              i can make a tilemap, i can make a character, but when i put them together i simply dont know anything about how to do the collision
              can anyone help me?

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: problems
« Reply #1 on: December 08, 2010, 07:10:49 pm »
posting your source code will help. basically, you then find  pxl you want to test for. divide the x and y positions by 8, and that's the position of the pixel in the tilemap. assuming 8 is your size, that is.


Offline feerik

  • LV2 Member (Next: 40)
  • **
  • Posts: 23
  • Rating: +0/-0
    • View Profile
Re: problems
« Reply #2 on: December 08, 2010, 07:17:54 pm »
first, thx for the quick awnser, second, its a tile map of8-10
so youre saying i need to do pxl-test?

(im new and i dont now how to post code)

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: problems
« Reply #3 on: December 08, 2010, 07:18:06 pm »
Hi and welcome, feerik. There are several ways to do collision detection, but the easiest way (without having to do a lot of math stuff) is to use pxl-Test(. Just check if the pixel(s) 8 pixels below your sprite are turned on (assuming you're using 8x8 sprites).

For example, if your sprite is at (X,Y), check with If pxl-Test(X,Y+8) or pxl-Test(X+7,Y+8) (the X+7 is to check for the rightmost column of pixels).

By the way, when you create help topics, you can get a lot more people to notice your post by using a title that tells us what you need help with.
« Last Edit: December 08, 2010, 07:21:47 pm by Deep Thought »




Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: problems
« Reply #4 on: December 08, 2010, 07:18:52 pm »
Collisions depend on what you're making, but try using this to Tilemap:

http://ourl.ca/4550

If you're doing  physics based game and you need really accurate physics, try Builderboy's routine (Which I hope he doesn't mind me posting):

Quote
If X1+W1>X2  AND  X2+W2>X1  AND  Y1+H1>Y2  AND  Y2+H2>Y1
there is a collision!
END

Where X and Y are position and W and H are width and Height.  As for collsion velocity tranfer, the equations are this:

V1 = (C*M2*(V2-V1)+M1*V1+M2*V2)/(M1+M2)
V2 = (C*M1*(V1-V2)+M2*V2+M1*V1)/(M2+M1)

Where V is velocity, M is mass, and C is a constant from 1-0.  1 being a perfectly elastic collision (no energy lost) and 0 being a perfectly inelastic collision (objects stick together).
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline feerik

  • LV2 Member (Next: 40)
  • **
  • Posts: 23
  • Rating: +0/-0
    • View Profile
Re: problems
« Reply #5 on: December 08, 2010, 07:19:39 pm »
is that the ? mark when you make a new topic?

Offline willrandship

  • Omnimagus of the Multi-Base.
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2953
  • Rating: +98/-13
  • Insert sugar to begin programming subroutine.
    • View Profile
Re: problems
« Reply #6 on: December 08, 2010, 07:20:01 pm »
Well, that works if you're using only B and W tiles

You can also check to see if the tile below you on the tilemap is movable or nonmoveable. This is substantially easier if either only one tile is moveable or only one tile is nonmoveable (moveable in this case meaning you can step on it)

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: problems
« Reply #7 on: December 08, 2010, 07:20:48 pm »
is that the ? mark when you make a new topic?

Nope, just name your post something like "Help with collision detection".




Offline feerik

  • LV2 Member (Next: 40)
  • **
  • Posts: 23
  • Rating: +0/-0
    • View Profile
Re: problems
« Reply #8 on: December 08, 2010, 07:20:59 pm »
thats exacly what im hoping for

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: problems
« Reply #9 on: December 08, 2010, 07:21:29 pm »
first, thx for the quick awnser, second, its a tile map of8-10
so youre saying i need to do pxl-test?

(im new and i dont now how to post code)



[code]
*code*
[/code]

will work like so:
Code: [Select]
i'm code

and no, you do not need to do pxl test. if you want, you can, but that is not tile-based.i'm saying if you have a tilemap like so:
Code: [Select]
01010101->GDB1
01000001
01000001
01010101
and each tile is 8x8, and your character was at (8,24) and you wanted to check to see if there's at tile beneath him(there is),and your character is 8 pixels tall, you'd do this:
Code: [Select]
8->X
24->Y
{Y/8*4+(X/8)+GDB1} //returns tile number at pixel position (x,y)


Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: problems
« Reply #10 on: December 08, 2010, 07:23:40 pm »
Well, that works if you're using only B and W tiles

You can also check to see if the tile below you on the tilemap is movable or nonmoveable. This is substantially easier if either only one tile is moveable or only one tile is nonmoveable (moveable in this case meaning you can step on it)

Yes, it only works for monochrome, but that's pretty much required if you have multiple objects and you're using accurate physics.
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: problems
« Reply #11 on: December 08, 2010, 07:24:39 pm »
Collisions depend on what you're making, but try using this to Tilemap:

http://ourl.ca/4550

If you're doing  physics based game and you need really accurate physics, try Builderboy's routine (Which I hope he doesn't mind me posting):

Quote
If X1+W1>X2  AND  X2+W2>X1  AND  Y1+H1>Y2  AND  Y2+H2>Y1
there is a collision!
END

Where X and Y are position and W and H are width and Height.  As for collsion velocity tranfer, the equations are this:

V1 = (C*M2*(V2-V1)+M1*V1+M2*V2)/(M1+M2)
V2 = (C*M1*(V1-V2)+M2*V2+M1*V1)/(M2+M1)

Where V is velocity, M is mass, and C is a constant from 1-0.  1 being a perfectly elastic collision (no energy lost) and 0 being a perfectly inelastic collision (objects stick together).

That routine is for collision between objects, not between an object and a tilemap, so thats not what he wants.

So you know how to make a tilemap you say?  How are you storing your data?  What do your sprites look like?

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: problems
« Reply #12 on: December 08, 2010, 07:25:30 pm »
I'd forgotten about that  :P

Yeah, nemo's routine is probably the way to go.
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline feerik

  • LV2 Member (Next: 40)
  • **
  • Posts: 23
  • Rating: +0/-0
    • View Profile
Re: problems
« Reply #13 on: December 08, 2010, 07:26:24 pm »
yes i use something like this
(test)
Code: [Select]
[01020202020202020203]->GBD1
[04050505050505050504]
...

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: problems
« Reply #14 on: December 08, 2010, 11:12:30 pm »
By the way, in your program, do you want the movement to be tile by tile or pixel by pixel? By tile by tile I mean for example assuming your tiles are 8x8 large, the character and enemies would move by 8 pixels intervals instead of 1. If you use smooth movement it might be a bit more complicated but it's doable. I don't really remember how, though, since it has been 4 months since I last used tilemapping in Axe.

Welcome on the forums by the way!