A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [F8] Inaccuracy when aiming (help please!)

  1. #1
    President PhobiK's Avatar
    Join Date
    Jan 2005
    Location
    Guatemala
    Posts
    918

    [F8] Inaccuracy when aiming (help please!)

    I am trying to make some mc's follow another one which is static. I've always got this fine but for some reason the mcs don't follow a straight line or do not aim at the mc correctly :s . I really don't get what's going on and in the game I'm working on it is needed that they follow a straight line.

    Here's an example for you to see:
    http://www.giddelcreations.com/other...y_test_f8.html

    The blue ones follow the mc by determining the distance in _x and _y in every frame, like this:
    Code:
    xq = 0.004*(_root.dude._x - _x);
    yq = 0.004*(_root.dude._y - _y);
    _x += xq;
    _y += yq;
    The red ones do something like that but instead of determining the distance on every frame they do it only once and the move at the same speed. These are the less accurate.

    The gray ones determine the angle of the mc in every frame and then follow it. Code goes like this:
    Code:
    var c:Number = 0;
    var xs:Number;
    var ys:Number;
    var mul:Number = Math.PI / 180;
    onEnterFrame = function () {
    	xq = _root.dude._x - _x;
    	yq = _root.dude._y - _y;
    	rot = Math.atan2(yq, xq) * 180/Math.PI;
    	xs = Math.cos(rot * mul) * 0.7;
    	ys = Math.sin(rot * mul) * 0.7;
    	_x += xs;
    	_y += ys; (...)
    Thanks so much for any help!

    You can download the source here: http://www.giddelcreations.com/other...ay_test_f8.fla
    This is MC. His _parents sent him to stop() by the super market to buy some _root beer if he wanted to gotoAndPlay() with his friends at the park later.

    This is my Blog!... The gaming Process
    Please check out my site: Giddel Creations

  2. #2
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    Coordinates of movie clip are not full Numbers, they are cut off after comma. Using coordinates over and over makes your calculations inaccurate. Try this way (for grey circle):
    Code:
    var myx:Number = _x;
    var myy:Number = _y;
    ...
    onEnterFrame = function () {
    	xq = (_root.dude._x - _x);
    	yq = (_root.dude._y - _y);
    	rot = Math.atan2(yq, xq) * 180/Math.PI;
    	xs = Math.cos(rot * mul) * 0.7;
    	ys = Math.sin(rot * mul) * 0.7;
    	
    	myx += xs;
    	myy += ys;
    	_x = myx;
    	_y = myy;
    	...

  3. #3
    President PhobiK's Avatar
    Join Date
    Jan 2005
    Location
    Guatemala
    Posts
    918
    Thanks bunches Tonypa!!! that woked quite perfect. Greatly appreciated! It's good to learn new things everyday
    This is MC. His _parents sent him to stop() by the super market to buy some _root beer if he wanted to gotoAndPlay() with his friends at the park later.

    This is my Blog!... The gaming Process
    Please check out my site: Giddel Creations

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