Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Collision Help
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Prince Pwn




PostPosted: Mon Jul 30, 2007 5:39 pm   Post subject: Collision Help

This should be a way easier problem to solve than the other one. In my Pokemon World applet, the collision detection I use for houses works perfectly and goes something along the lines of this:

Java:

            // Barriers
            if (ashX + ashWidth >= X && ashX <= X + NPC.getWidth (null) && ashY + ashHeight >= Y && ashY <= Y + NPC.getHeight (null))
            {
                if (pressed == "up") // Your house
                    ashY = Y + NPC.getHeight (null);
                if (pressed == "down")
                    ashY = Y - NPC.getHeight (null);
                if (pressed == "right")
                    ashX = X - NPC.getWidth (null);
                if (pressed == "left")
                    ashX = X + NPC.getWidth (null);
            }


It does stop the player from going through an NPC, but say I'm on the left of the NPC going right, and I'm right against the NPC from the right and press up, I teleport below the NPC. Or if I press down, I'll appear above it. If I'm on the left going up or down, same thing. Look at the applet on the site, you'll see what I mean.
Sponsor
Sponsor
Sponsor
sponsor
Dan




PostPosted: Mon Jul 30, 2007 5:58 pm   Post subject: RE:Collision Help

Rather then reseting ashs postion when he hits somthing you should simpley not let him move in that direction.

so somthing like:

if up && ash not hiting somthing if he goses up then
move ash up
else if........


Obevesly that is very pesdo code but you whould just have to compare what his postion whould be if he whent up and see if that hits somthign befor aucataly moving him up.

Also for games like pokemon a title system whould be better then seting the coselsion dimtetions for each house. You can find out more about title systems and rpgs by using our sreach function.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Prince Pwn




PostPosted: Tue Jul 31, 2007 7:49 pm   Post subject: RE:Collision Help

Hah all of a sudden something snapped. All I did was remove the >= and <= and replaced with < and > then boom. Perfect collision. Thanks for the suggestion though, I will take it into consideration in the near future.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: