Results 21 to 40 of 40
Thread: Collision Detection?
- 09-04-2011, 08:24 PM #21
- 09-04-2011, 08:40 PM #22
Re: Collision Detection?
Can you explain what is supposed to happen when the WASD keys are pressed and when the white square goes to the side of the black square?
- 09-04-2011, 09:04 PM #23
Re: Collision Detection?
I think I actually managed to solve it.
Thanks for all help,
AhCurrently Developing a Game Called Loaie, You Can Download It From "The Loaie Website".
- 09-04-2011, 09:05 PM #24
Re: Collision Detection?
Part of your problem was that the object is larger than the point at the top left corner.
Some suggestions:
Java Code:class ac extends JPanel { public int speed = 1; Rectangle[] rec = {new Rectangle(100, 100, 100, 100)}; //Rectangle Rectangle pt = new Rectangle(120, 130, 5,5 ); //Current Character Position; in the key listeners pt.y -= speed; and in the paint method: g.setColor(Color.BLACK); g.fillRect(rec[0].x, rec[0].y, rec[0].width, rec[0].height); //Level; g.setColor(Color.WHITE); g.fillRect(pt.x, pt.y, pt.width, pt.height);Last edited by Norm; 09-04-2011 at 09:08 PM.
- 09-04-2011, 09:18 PM #25
Re: Collision Detection?
Now I encountered even one more problem...
My character is walking in the white areas, so he is walking into the cubes.
But when he are supposed to change cube, I mean when I add,
if(rec[0].contains(pt) *Here the thing I want to show starts* || rec[1].contains(pt))
he stays in the rec[0] area. :-/ How can I solve this?Currently Developing a Game Called Loaie, You Can Download It From "The Loaie Website".
- 09-04-2011, 09:19 PM #26
Re: Collision Detection?
Oh, did'nt see you wrote something. I'll take a look.
Currently Developing a Game Called Loaie, You Can Download It From "The Loaie Website".
- 09-04-2011, 09:36 PM #27
Re: Collision Detection?
But he is still getting stuck in the walls.
Currently Developing a Game Called Loaie, You Can Download It From "The Loaie Website".
- 09-04-2011, 09:39 PM #28
Re: Collision Detection?
What stops the moving of the small white square when you are pressing one of the WASD keys?
Look at your logic there.
Do you need to move the small white square back inside of the black square.
- 09-05-2011, 09:20 PM #29
Re: Collision Detection?
He stops when hitting the walls. It's like he is going one pixel too much.
Is there any way to tell him that he can't walk that extra pixel?Currently Developing a Game Called Loaie, You Can Download It From "The Loaie Website".
- 09-05-2011, 09:24 PM #30
Re: Collision Detection?
What does your logic do when HE hits a wall? What happens to future presses of the key that moved HIM to hit the wall.He stops when hitting the walls
Test BEFORE changing the x,y if HE will hit a wall and don't move HIM if the new x,y hits a wall.Is there any way to tell him that he can't walk that extra pixel?
Have the "boundary" wall one or two pixels inside of the visual wall.
- 09-06-2011, 05:13 PM #31
Re: Collision Detection?
Hmm, what do you mean with a boundary wall? :o
Currently Developing a Game Called Loaie, You Can Download It From "The Loaie Website".
- 09-06-2011, 05:23 PM #32
Re: Collision Detection?
A rectangle inside of the visual rectangle.
Visual at 10, 10, 100, 100
boundary at 11, 11, 98, 98
Not really necessary, your code should detect a wall and not go past or into it.
- 09-06-2011, 06:37 PM #33
Re: Collision Detection?
Are you sure there are no other word then constaints(); i can use in order to see the walls?
He is going one pixel too much every time.Currently Developing a Game Called Loaie, You Can Download It From "The Loaie Website".
- 09-06-2011, 06:44 PM #34
Re: Collision Detection?
Your code should detect that BEFORE the movementHe is going one pixel too much every time.
Say the wall is at x = 100
and the object is at x = 99 and moving to the right (+x)
If the distance to move is 1, 99+1 is into the wall => Don't make the move, stay at x=99
- 09-06-2011, 06:46 PM #35
Re: Collision Detection?
Do you mean methods?no other word then constaints()
Read the API doc to see if any other methods would be of use.
- 09-06-2011, 09:26 PM #36
Re: Collision Detection?
Hmm, the code is testing it before the movement :-oYour code should detect that BEFORE the movement
Say the wall is at x = 100
and the object is at x = 99 and moving to the right (+x)
If the distance to move is 1, 99+1 is into the wall => Don't make the move, stay at x=99
How do you want me to stay at 99? -.-Currently Developing a Game Called Loaie, You Can Download It From "The Loaie Website".
- 09-06-2011, 09:33 PM #37
Re: Collision Detection?
Basically: if the move will be into the wall do not make it. What order can you set, test and change the values that will prevent moving into the wall. Look at the order you are doing those things.
Post the lines of code you are using to keep the object from moving into a wall.
- 09-07-2011, 07:43 AM #38
Re: Collision Detection?
Can't I like test collision for only one side of the cube?
For an example when it hits the left wall the left movement stops.
That would make me to solve it.
Thanks,
AhCurrently Developing a Game Called Loaie, You Can Download It From "The Loaie Website".
- 09-07-2011, 01:17 PM #39
Re: Collision Detection?
Why only one side? Is this just for testing some new code?Can't I like test collision for only one side of the cube?
Post the lines of code you are using to keep the object from moving into a wall.
- 09-07-2011, 04:55 PM #40
Re: Collision Detection?
I think I actually managed to solve it now.
Made 2 different rectangles, one for left/up & one for right/down.
Works perfect!
Thanks!Currently Developing a Game Called Loaie, You Can Download It From "The Loaie Website".
Similar Threads
-
Collision Detection, a little bit buggy.
By iamsothecoolest in forum New To JavaReplies: 10Last Post: 08-04-2011, 12:03 AM -
Java3D collision detection
By abbeywell in forum Java GamingReplies: 5Last Post: 04-27-2011, 02:33 PM -
Really Need help with some collision detection
By Harwad in forum New To JavaReplies: 1Last Post: 01-23-2011, 12:38 AM -
Collision Detection
By dotabyss in forum Java GamingReplies: 0Last Post: 03-14-2010, 06:13 PM -
Collision Detection (Game)
By mscwd in forum Sun Java Wireless ToolkitReplies: 0Last Post: 01-28-2008, 08:34 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks