Results 1 to 1 of 1
  1. #1
    Mutt is offline Member
    Join Date
    Apr 2013
    Posts
    2
    Rep Power
    0

    Angry Intersection/gravity problem - Weird as hell

    Okay, so I have this code of my intersection and this checks for the intersection of the left, right and bottom sides of the player.
    What is happening is:
    My player falls a little bit, hits the ground and stops, then I walk to the left, it works fine, he stops when he hits the wall, but when I walk to the right side, he hits the wall, stops walking to the right, but suddenly starts sinking through the ground as if there was no ground.
    Here's the all the code that has something to do with the movement(I haven't worked on intersectTop yet, since I can't get the others to work, that is the reason it is blank):
    Java Code:
    public void loop() {
    		move();
    		gravitate();
    	}
    
    	public boolean intersectRight() {
    		for (int x = 0; x < xTiles; x++) {
    			for (int y = 0; y < yTiles; y++) {
    				if (player.intersects(blocks[x][y]) && blocks[x][y].solid) {
    					if (player.x + player.width >= blocks[x][y].x
    							&& player.x + player.width < blocks[x][y].x
    									+ (blockSize / 4)
    							&& player.y + player.height - (blockSize / 2) > blocks[x][y].y) {
    						player.x = blocks[x][y].x - blockSize;
    						System.out.println("Right: true");
    						return true;
    					}
    				}
    			}
    		}
    		return false;
    	}
    
    	public boolean intersectLeft() {
    		for (int x = 0; x < xTiles; x++) {
    			for (int y = 0; y < yTiles; y++) {
    				if (player.intersects(blocks[x][y]) && blocks[x][y].solid) {
    					if (player.x <= blocks[x][y].x + blockSize
    							&& player.x > blocks[x][y].x + (blockSize / 4)
    							&& player.y + player.height - (blockSize / 2) > blocks[x][y].y) {
    						player.x = blocks[x][y].x + blockSize;
    						System.out.println("Left: true");
    						return true;
    					}
    				}
    			}
    		}
    		return false;
    	}
    
    	public boolean intersectBot() {
    		for (int x = 0; x < xTiles; x++) {
    			for (int y = 0; y < yTiles; y++) {
    				if (player.intersects(blocks[x][y]) && blocks[x][y].solid) {
    					if (!intersectLeft() && !intersectRight()) {
    						if (player.y + player.height >= blocks[x][y].y) {
    						
    							player.y = player.y
    									- (player.y + (player.height) - blocks[x][y].y);
    						}
    						return true;
    					}
    				}
    			}
    		}
    		return false;
    	}
    
    	public boolean intersectTop() {
    
    		return false;
    	}
    
    	public void move() {
    		player.x += player.dx;
    		player.y += player.dy;
    	}
    
    	public void gravitate() {
    		if (!intersectBot()) {
    			player.dy += (grav * gravMultiplier);
    			if (player.dy > 15) {
    				player.dy = 15;
    			}
    		} else {
    			player.dy = 0;
    		}
    	}
    Last edited by Mutt; 04-21-2013 at 02:40 PM. Reason: Adding some info

Similar Threads

  1. string array hell (please help!!)
    By mbw290 in forum New To Java
    Replies: 1
    Last Post: 11-30-2012, 12:31 AM
  2. Take gravity of a polygon
    By hqt in forum Java 2D
    Replies: 5
    Last Post: 01-27-2012, 12:05 PM
  3. Thread hell - Please Help!!
    By lcmorley in forum Threads and Synchronization
    Replies: 3
    Last Post: 01-03-2012, 06:24 PM
  4. I need help with a gravity simulator!
    By Karly_Kute_X in forum New To Java
    Replies: 5
    Last Post: 12-10-2011, 07:40 PM
  5. how to apply gravity in tossing an egg
    By santhoshnanjappa in forum New To Java
    Replies: 1
    Last Post: 07-01-2009, 03:26 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •