here is video showing you + collisions dont work
hZs_OJbPi6Q
the player box moves down on screen when its suppose to stay in the middle O.o never seen it before
My Tick Method
public void tick(){
float moveAmountu = (float) (jumpingSpeed * fixDt);
float moveAmountd = (float) (fallingSpeed * fixDt);
float moveAmountl = (float) (speedLeft * fixDt);
float moveAmountr = (float) (speedRight * fixDt);
if(Gdx.input.isKeyJustPressed(Keys.SPACE) && !toggleJump && !jumping){
jumping = true;
toggleJump = true;
falling = false;
}
if(falling){
fallPlayer(moveAmountd);
}
if(jumping){
jumping(moveAmountu);
}
camera.position.x = pos.x;
camera.position.y = pos.y;
camera.update();
}
Jump and Falling Code where i check Collision
public void jumping(float speed) {
if(!Collision.CollisionPlayerBlock(
new Point((int) (pos.x) ,
(int) (pos.y - speed)),
new Point((int) (pos.x + width) ,
(int) (pos.y - speed)) )){
if(jumpingSpeed > 0){
jumpingSpeed -= .09;
}
if(jumpingSpeed <= 0){
falling = true;
jumping = false;
jumpingSpeed = defaultjumpingSpeed;
}
pos.y+=speed;
}else{
jumpingSpeed = defaultjumpingSpeed;
falling = true;
jumping = false;
}
}
public void fallPlayer(float speed) {
if(!Collision.CollisionPlayerBlock(
new Point((int) (pos.x ) ,
(int) (pos.y + height + speed)),
new Point((int) (pos.x + width) ,
(int) (pos.y + height + speed)) )){
if(fallingSpeed != maxSpeed*16){
fallingSpeed += .1;
}
if(fallingSpeed >= maxSpeed*16){
fallingSpeed = maxSpeed*16;
}
pos.y-=speed;
}else{
toggleJump = false;
fallingSpeed = 0;
}
}
My Collision Class
public static boolean CollisionPlayerBlock(Point p1, Point p2){
for(int x = 0; x < 50;x++){
for(int y = 0; y < 50;y++){
Block[][] blocks = World.getPlayer().getWorld().getLoadedChunkBlocks();
if(blocks[x][y].isSolid()){
if(blocks[x][y].contains(p1) || blocks[x][y].contains(p1)){
return true;
}
}
System.out.println(blocks.length+"");
}
}
return false;
}
My Contains Method <-- might be the one that fails me
public boolean contains(Point point) {
double px = point.getX();
double py = point.getY();
if(px < blockPos.x){
if(px > blockPos.x){
if(py < blockPos.y){
if(py > blockPos.y){
System.out.println("TRUE");
return true;
}
}
}
}
return false;
}
My Whole Player Class
public class Player implements InputProcessor {
private Vector2 pos = new Vector2(50*50, 100*80);
private Vector2 vol = new Vector2();
private World world;
private OrthographicCamera camera;
private int width = 16, height = 32;
public float fixDt = 60f/60F;
public static float maxSpeed = 2.9F;
public boolean falling,isInAir,jumping,isAlive,toggleJump,moving, space, running = false;
public float speedLeft = 0;
public float speedRight = 0;
public float fallingSpeed = 3;
public float defaultjumpingSpeed = 3.56f;
public float jumpingSpeed = defaultjumpingSpeed;
public Player(OrthographicCamera camera, World world) {
this.camera = camera;
this.world = world;
}
public void draw(SpriteBatch batch){
}
public void tick(){
float moveAmountu = (float) (jumpingSpeed * fixDt);
float moveAmountd = (float) (fallingSpeed * fixDt);
float moveAmountl = (float) (speedLeft * fixDt);
float moveAmountr = (float) (speedRight * fixDt);
if(Gdx.input.isKeyJustPressed(Keys.SPACE) && !toggleJump && !jumping){
jumping = true;
toggleJump = true;
falling = false;
}
if(falling){
fallPlayer(moveAmountd);
}
if(jumping){
jumping(moveAmountu);
}
camera.position.x = pos.x;
camera.position.y = pos.y;
camera.update();
}
public void jumping(float speed) {
if(!Collision.CollisionPlayerBlock(
new Point((int) (pos.x) ,
(int) (pos.y - speed)),
new Point((int) (pos.x + width) ,
(int) (pos.y - speed)) )){
if(jumpingSpeed > 0){
jumpingSpeed -= .09;
}
if(jumpingSpeed <= 0){
falling = true;
jumping = false;
jumpingSpeed = defaultjumpingSpeed;
}
pos.y+=speed;
}else{
jumpingSpeed = defaultjumpingSpeed;
falling = true;
jumping = false;
}
}
public void fallPlayer(float speed) {
if(!Collision.CollisionPlayerBlock(
new Point((int) (pos.x ) ,
(int) (pos.y + height + speed)),
new Point((int) (pos.x + width) ,
(int) (pos.y + height + speed)) )){
if(fallingSpeed != maxSpeed*16){
fallingSpeed += .1;
}
if(fallingSpeed >= maxSpeed*16){
fallingSpeed = maxSpeed*16;
}
pos.y-=speed;
}else{
toggleJump = false;
fallingSpeed = 0;
}
}
@Override
public boolean keyDown(int arg0) {
return false;
}
@Override
public boolean keyTyped(char arg0) {
return false;
}
@Override
public boolean keyUp(int arg0) {
return false;
}
@Override
public boolean mouseMoved(int arg0, int arg1) {
return false;
}
@Override
public boolean scrolled(int scrolls) {
if(scrolls < 1){
camera.zoom -= 0.1f;
camera.update();
}else{
camera.zoom += 0.1f;
camera.update();
}
return false;
}
@Override
public boolean touchDown(int arg0, int arg1, int arg2, int arg3) {
return false;
}
@Override
public boolean touchDragged(int arg0, int arg1, int arg2) {
return false;
}
@Override
public boolean touchUp(int arg0, int arg1, int arg2, int arg3) {
return false;
}
public void drawShapes(ShapeRenderer shapeR) {
shapeR.rect(pos.x , pos.y, width, height);
}
public World getWorld() {
return world;
}