java - How to handle collision after detecting it -


i've been trying past few days put simple collision simple game. i've looked in lots of places on internet haven't found helpful. i'm using bounding boxes , want player box stop when hits block of 4 sides (and not stuck or bounce against block). doesn't sound difficult i've found incredibly difficult. wanna know code need put in if statement's brackets, i've read , heard theory can take. please if can.

if(bb_collide(player,block)){  //detection works fine,                                        //just not sure afterwards       }     else{         player.setx((player.getx() + velx));         player.sety((player.gety() - vely));         player.set_coll(player.getx(),player.gety(),player.getwidth(),player.getheight());         block.set_coll(block.getx(),block.gety(),block.getwidth(),block.getheight());      } 

i figured out, having couple of bad days, sorry if had bad attitude or got wanted to. heres did if anyone's interested because works 1 moving object (mover) bumping stationary object (sitter). finds distance between sides collide , sets velocity distance minus few doesnt overlap. had bounding boxes rendering see overlapped. replies!

    public void fix_vel(player mover, terrain sitter){      if(sitter.coll_box.contains(mover.getx() + mover.getheight() + mover.getvelx(), mover.gety()) ||              sitter.coll_box.contains(mover.getx() + mover.getheight() + mover.getvelx(), mover.gety() + mover.getheight()) ){        //mover top right , bottom right coords right collision testing          mover.setvelx(sitter.getx() - (mover.getx() + mover.getwidth()) - 2);      }      if(sitter.coll_box.contains(mover.getx() + mover.getvelx(), mover.gety()) ||              sitter.coll_box.contains(mover.getx() + mover.getvelx(), mover.gety() + mover.getheight()) ){                               //mover top left + bottom left coords left collision testing          mover.setvelx((sitter.getx() + sitter.getwidth()) - mover.getx() + 2);        }      if(sitter.coll_box.contains(mover.getx(), mover.gety() + mover.getvely()) ||              sitter.coll_box.contains(mover.getx() + mover.getwidth(), mover.gety() + mover.getvely())){                                 //mover top left + top right coords top collision testing          mover.setvely((sitter.gety() + sitter.getheight()) - mover.gety() + 2);       }      if(sitter.coll_box.contains(mover.getx(), mover.gety() + mover.getheight() + mover.getvely()) ||                                //mover bottom left , bottom right coords bottom collision testing             sitter.coll_box.contains(mover.getx() + mover.getwidth(), mover.gety() + mover.getheight() + mover.getvely())){          mover.setvely(sitter.gety() - (mover.gety() + mover.getheight()) - 2);         jumping = false;          if(mover.getvely() < 0)             mover.setvely(0);         } } 

you don't how each box controlled, i'm not sure want. if detection works, don't allow object move if cause collision.

ps: i wanna know code need put in if statement's brackets, i've read , heard theory can take. honest, attitude, you're not going far , you're going need people's help. game programming requires decent amount of mathematical intuition. trigonometry, calculus , linear algebra essential.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

keyboard - C++ GetAsyncKeyState alternative -

android - java.net.UnknownHostException(Unable to resolve host “URL”: No address associated with hostname) -