A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Oh I wish i remembered trig stuff

  1. #1
    Senior Member
    Join Date
    Apr 2006
    Posts
    1,059

    Oh I wish i remembered trig stuff

    I have this trajectory
    bullet._t = ((_root.MainChar_mc._rotation+angleCorrection)*Mat h.PI)/180;
    bullet._x += Math.cos(this._t)*15;
    bullet._y += Math.sin(this._t)*15;

    From this how can i tell weather the bullet is moving up on the stage down on the stage left right?

    basically how can i get a function that if this bullet is moving straight up it returns 0 if its going directly to the right it returns 90
    if its directly down 180 and dead left would be 270(relative to the stage)

    im sure this one will be a piece of cake for dmonkey or one of you other sly math guys

  2. #2
    Senior Member ozmic66's Avatar
    Join Date
    Oct 2005
    Posts
    472
    a simple getAngle function should do it:

    Code:
    function getAngle(xDiff,yDiff){
    	radians = Math.atan2(yDiff, xDiff);
    	if (yDiff<0) {
    		radians += (2*Math.PI);
    	}
    	degrees = radians/(Math.PI/180)-180;
    	return degrees
    }
    i think that here 0 degrees means facing up, but you should check just to make sure

  3. #3
    Senior Member
    Join Date
    Apr 2006
    Posts
    1,059
    awesome thanks

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center