Forum Topic: trigo movement innacurate

(94 views • 6 replies)

This topic is 1 page long.

<< < > >>
None

iluvAS

Reply To Post Reply & Quote

Posted at: 9/27/09 06:08 AM

iluvAS NEUTRAL LEVEL 07

Sign-Up: 11/18/07

Posts: 271

defender game... lots of enemies.... and innaccurate when trying to attack main character.

//code in creating mobs
var enemy:Enemy=new Enemy();
enemy.rotation=Math.random()*360;
eXspd.push(Math.cos((enemy.rotation-90)*Math.PI/180));
eYspd.push(Math.sin((enemy.rotation-90)*Math.PI/180));//calculate the xspd and yspd
enemy.x=500+eXspd[eXspd.length-1]*600;
enemy.y=300+eYspd[eYspd.length-1]*600;// set the mobs offscreen with respect to the mid of the stage where the main character is
eArray.push(addChild(enemy));

the problem was that when the mob tries to come and attack the main character its inaccurate and smtimes never even comes into contact with the main character.

//code to move 
for(var i:uint=0;i<eArray.length;i++){
	if(eArray[i]!=null){
		eArray[i].x-=eXspd[i]
		eArray[i].y-=eYspd[i]
	}
}

erm can someone help out =(


None

iluvAS

Reply To Post Reply & Quote

Posted at: 9/27/09 06:30 AM

iluvAS NEUTRAL LEVEL 07

Sign-Up: 11/18/07

Posts: 271

basically i wanna get one object to move to another set of coordinate interms of angles... how do i do it?


None

dELtaluca

Reply To Post Reply & Quote

Posted at: 9/27/09 06:36 AM

dELtaluca LIGHT LEVEL 20

Sign-Up: 04/16/04

Posts: 5,559

The problem doesn't stem from your logic, but from the fact that coordinates in flash are rounded to the nearest 20th of a pixel, which means that over time, large innacuracies will build up.

Your solution should be to store the position of the objects in normal variables which will not be auto-rounded, and then simply render the object at that position.

aka: instead of:

obj.x += offset;

do:

obj.px += offset; //(where px is a normal Number variable on obj)
obj.x = obj.px;

My social worker says im special!

BBS Signature

None

iluvAS

Reply To Post Reply & Quote

Posted at: 9/29/09 01:10 AM

iluvAS NEUTRAL LEVEL 07

Sign-Up: 11/18/07

Posts: 271

erm im using AS3 so erm the px py values are stored in a parallel array so each bullet can access em

(i duno how to do classes yet)

so erm... it does show a significant improvement but there still some "jerkin" xD the bullets would suddenly jerk out of place like around 50px max. when there are lots of em instances... and erm u also said the variable has to be a number?.. erm well i jus realised.. how do i declare that a certain element in an array is a number O_o????

help plox


None

fjgamer

Reply To Post Reply & Quote

Posted at: 9/29/09 01:23 AM

fjgamer EVIL LEVEL 08

Sign-Up: 08/15/08

Posts: 268

Why not just use a tween library?


None

iluvAS

Reply To Post Reply & Quote

Posted at: 9/29/09 01:27 AM

iluvAS NEUTRAL LEVEL 07

Sign-Up: 11/18/07

Posts: 271

whaaaa?!?!?!?

whats that? and how do i use it O_O


None

fjgamer

Reply To Post Reply & Quote

Posted at: 9/29/09 01:57 AM

fjgamer EVIL LEVEL 08

Sign-Up: 08/15/08

Posts: 268

Well, there's the default tweening, built into Flash IDE. Then, there are many different tweening engines out there. My personal choice is Tweener. There's also gTween, TweenLite, TweenMax and FUSE, just to name a few.

Here's Tweener: http://code.google.com/p/tweener/

Hope I helped.


All times are Eastern Standard Time (GMT -5) | Current Time: 10:10 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!