Thread: Some angle help
View Single Post
  #1  
Old 10-28-2007, 10:42 PM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
Some angle help

I'm working on some fairly basic object physics on Maloria, where hitting an object will make it move. I'm at the part where I need it to kind of bounce off a wall when it collides with it a bit, but I'm having trouble figuring out how I would do that. Here's what I have:
PHP Code:
function onCreated() {
  if (!(
"function_domove" in  this.joinedclasses))
    
join("function_domove");
  
this.moving false;
  
this.canhurt false;
  
this.distgone 0;
  
this.lastpos = {this.xthis.y};
}
function 
onActionHit(damageaccuracyeffectsaccpxpy) {
  
this.dist 0;
  
this.distgone 0;
  
this.speed 0;
  
this.canhurt false;
  
this.angle getangle(px this.xpy this.y);
  if (
this.angle degtorad(180))
    
this.angle -= degtorad(180);
  else 
this.angle += degtorad(180);
  
this += degtorad(int(random(-1011)));
  
temp.friction this.weight damage;
  if (
temp.friction >= 1this.dist 0;
  else 
this.dist .75 temp.friction;
  
this.moving true;
  
this.speed damage/5;
  if (
this.speed 5this.canhurt true;
  
onTimeOut();
}
function 
onTimeOut() {
  if (
this.moving) {
    if (
this.distgone this.dist) {
      
temp.dir getDir(this.lastpos[0]-this.x,this.lastpos[1]-this.y);
      
this.dir temp.dir;
      
this.lastpos = {this.xthis.y};
      
temp.move doMove(this.anglethis.dist/this.speed);
      if (
temp.movethis.distgone += this.dist/this.speed;
      else {
        
//collision stuff here
      
}
      if (
this.canhurt)
        
triggeraction(this.x+1+vecx(temp.dir)*(this.dist/this.speed), this.y+1+vecy(temp.dir)*(temp.dist/this.speed),"Hit",this.dist/2,40);
      
setTimer(0.05);
    }
    else 
this.moving false;
  }

The class function_domove would be Zero's movement system. ("doMove(angle, speed)")...I need it to move "this.dist/this.speed" distance...but the problem if figuring out how to get the angle at which it would bounce off...
__________________

Quote:
*SlikRick: so should I even ask about your aim status?
*Xor: well if you want to
*Xor: but i am LARPING
*SlikRick: While on a computer?
*Xor: yes
*Xor: in my living room
*SlikRick: ahh
*Xor: i have a fort setup to hide from beasts
Reply With Quote