Thread: Some angle help
View Single Post
  #19  
Old 11-03-2007, 09:53 PM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
Quote:
Originally Posted by coreys View Post
I only have the angles split into x and y because of checking if it's hitting a wall vertically or horizontally. That's the only way I could think of doing it.
This is probably why it's not functioning like you'd want it to. sin() and cos() already split an angle into y- and x-components. So, you only need a single angle.

Here is an example:
PHP Code:
//#CLIENTSIDE
function onCreated() {
  
this.img showimg(2001,"block.png",40,40);
  
this.img.layer 7;
  
this.img.angle pi/8;
  
this.img.velocity 8;
  
this.img.getimgwidth(this.img.image);
  
this.img.getimgheight(this.img.image);
  
onTimeout();
}
function 
onTimeout() {
  
with (this.img) {
    for (
temp.i=0temp.i<this.velocitytemp.i++) {
      if (
abs(screenwidth/2-this.x-cos(this.angle)-this.w/2)<screenwidth/2-this.w/2)
        
this.+= cos(this.angle);
      else 
        
this.angle pi-this.angle;
      if (
abs(screenheight/2-this.y+sin(this.angle)-this.h/2)<screenheight/2-this.h/2)
        
this.-= sin(this.angle);
      else 
        
this.angle = -this.angle;
    }
  }
  
timeout 0.05;

__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/
Reply With Quote