Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Why isn't my collision working?

  1. #1
    Junior Member
    Join Date
    Jul 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Why isn't my collision working?

    	private void checkForCollision() {
            for(int i = 0; i < world.arrayNum; i++){
    		if(world.isBlock[i] && playerRect.intersects(world.blocks[i])) {
    		xDirection(0);
                    yDirection(0);
                    System.out.println("HIT!");
     
    		}
            }
    	}

    I have this method constantly updated and everytime i do hit the block it does print out HIT but it never stops my player from moving into it. Do you see anything wrong?


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Why isn't my collision working?

    I see a method being overworked. "checkForCollision" in my book would return a boolean, and would not adjust xDirection and yDirection directly, but that is just a side issue I am certain.
    Without seeing how this method is actually being used, not much we can say about what is wrong with it.
    Use some printlns to find out what is happening when

Similar Threads

  1. Why isn't this code working?
    By tai8 in forum What's Wrong With My Code?
    Replies: 24
    Last Post: March 19th, 2012, 07:00 PM
  2. Why isn't this code working?
    By tai8 in forum What's Wrong With My Code?
    Replies: 33
    Last Post: March 12th, 2012, 03:23 PM
  3. Can someone please tell me why my do while loop isn't working?
    By JavaAsh in forum What's Wrong With My Code?
    Replies: 14
    Last Post: October 20th, 2011, 03:52 PM
  4. Why isn't this working?
    By javapenguin in forum What's Wrong With My Code?
    Replies: 14
    Last Post: January 21st, 2011, 04:08 PM
  5. newLine isn't working
    By The_Mexican in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 8th, 2011, 11:42 AM