|
Page 1 of 1 |
|
Posted: Mon, 7th Apr 2014 09:50 Post subject: Know anyone who can dev in AS3? |
|
 |
From my experience it's pretty much just like JS
I can do pretty much everything but I want to run what I do by someone who knows what's what and perhaps they can help with the more complex stuff
I can pay for their time
Thanks
|
|
Back to top |
|
 |
|
Posted: Mon, 7th Apr 2014 10:23 Post subject: |
|
 |
Sorry, I have no experience with AS3 and that bit of stuff I did with AS2 is compared to your knowledge laughable 
|
|
Back to top |
|
 |
|
Posted: Mon, 7th Apr 2014 12:20 Post subject: |
|
 |
Last edited by Interinactive on Tue, 5th Oct 2021 02:18; edited 1 time in total
|
|
Back to top |
|
 |
|
|
Back to top |
|
 |
|
Posted: Mon, 7th Apr 2014 13:54 Post subject: |
|
 |
You can also pm me with a bit more details, I'd love to help IF that is actually something that would work.
Maybe I could at least post pseudo code or similar js code and you transform it to AS3? I should at least be able to maybe give some help with the algorithms etc.
|
|
Back to top |
|
 |
|
|
Back to top |
|
 |
|
|
Back to top |
|
 |
|
Posted: Mon, 7th Apr 2014 15:34 Post subject: |
|
 |
Last edited by Interinactive on Tue, 5th Oct 2021 02:18; edited 1 time in total
|
|
Back to top |
|
 |
|
Posted: Mon, 7th Apr 2014 15:49 Post subject: |
|
 |
Yes, look at the facing function, it just takes the angle you have and divides it through 8
A full circle has 360 degrees. Let's split it into 8 smaller pieces -> 45 degree per slice.
0 = looking down
1 = looking down right
2 = looking right
3 = looking right up
4 = looking up
5 = looking left up
6 = looking left
7 = looking left down
Now let's say the angle between your char and the target is 170° ok?
170/45 = 3.77778 -> rounded = 4 <= looking up, perfect
This means that if your target is anywhere between >=157.5° and < 202.5° degree, your char will look up
ONE oddity is there though, the 8 (modulo)-> it ensures, that we always have only 8 slices (0 to 7) and anything above 337,5° is also counted as 0, meaning looking down, which is exactly what we want 
|
|
Back to top |
|
 |
|
Posted: Mon, 7th Apr 2014 16:01 Post subject: |
|
 |
Here an image, so that it is easier to grasp. Why this works is, because the mathematical round takes everything from round(2.5) to round(3.4999)... and returns 3. If you would ceil , it would ALWAYs go for the higher number, f.e. ceil(2.1) = 3 and even ceil(2.0001) = 3. floor would always round down to the smallest number => floor(2.99999) = 2.
And the rest in there is nothing magical. I just take point1 and point2 and make a basic substraction to get the difference in x and y. You then just pass these on to the atan2 function, which then returns something between 0 and 180 degrees and if it's on the left hand side it returns -0 to -180 degrees. Because this is not so nice to work with and might be confusing at times, I just add 360 degrees (Math.PI*2) to the calculation. So you'll always get nice 360° values
IF you want we could also have a skype session, might be easier to ask and answer questions? Also you'd her some proper german ACKZENT!
|
|
Back to top |
|
 |
|
Posted: Mon, 7th Apr 2014 16:23 Post subject: |
|
 |
And a step by step calculation guide:
Your point is in the middle of a 200x200 screen, so it is at 100,100
Player.x = 100
Player.y = 100
The target is at the very top, slightly to the right of the player at 110,0
Target.x = 110
Target.y = 0
The delta between the two is the distance of each axis. This counts how we have to move from our player to the target.
Delta.x = Target.x - Player.x = 10
Delta.y = Target.y - Player.y = -100
To test if this is true, let's look at this calculation
Player.x + Delta.x = Target.x => 100 + 10 = 110 <= correct
Player.y + Delta.y = Target.y => 100 + -100 = 0 <= correct
The atan2 function (available in most programming languages) just takes this delta values and spits out the direction in RADIANS.
You can convert radians very easily to our normal degree system by multiplying the radian value with 180/PI
This works because a full circle has 2*PI radian and this is the same as 360°.
0 degree = 0 radian
180 degree = 3.1415... radian
360 degree = 6.283... radian
Degree to radian conversion: 360° / (180/PI) = 6.28 radian
radian to degree conversion: 6.28 * (180/PI) = 360°
From now on let's always assume that all of our calculations are in degree.
atan2 returns any value from 0 to 180 degree for everything on the right and side of the circle. One degree more (thus entering the left hand side of the circle), returns -180 degree and if you move further towards a full circle you get to -1° and then 0 again.
This is not very practicaly for our caluclations, so we just check if the result we have is negative and if so, we just add 360 to the result.
This results in the following:
for degree -> resulting degree after check
10° => 10°
150° => 150°
-170° (this is 10 degree over into the left top part of our circle) => 190° because -170+360 = 190
-10° => 350°
This is the exact behavior we want.
This means that atan2(Delta.x, Delta.y) + 360 => returns ~175° for our calculations.
Now we have to find the facing direction. For this look at the image. 175°/45° = 3.8888889° => round(3.88889) = 4 <= this is the facing value!
Extra:
Thanks to pythagoras we know that A²+B²=C² so we can calculate the actual distance from the target and player=>
sqrt(delta.x² + delta.y²) = distance
in JS this would be
var distance = Math.sqrt(delta.x*delta.x + delta.y*delta.y); //(I think delta.x*delta.x is faster than Math.pow(delta.x,2);
=> NFOrce GIF plugin <= - Ryzen 3800X, 16GB DDR4-3200, Sapphire 5700XT Pulse
Last edited by PumpAction on Mon, 7th Apr 2014 16:28; edited 1 time in total
|
|
Back to top |
|
 |
|
Posted: Mon, 7th Apr 2014 16:26 Post subject: |
|
 |
Looking at AS3, this seems to be really easy to port! If you need help with that just write here or PM me
BTW, I updated the http://pumpaction.prestige-gaming.net/forphil/ so that it also shows the target.x, target.y and the delta.x, delta.y and the distance, so that you can follow my demo calculations in the previous post.
|
|
Back to top |
|
 |
|
Posted: Tue, 8th Apr 2014 09:41 Post subject: |
|
 |
Mind you, I don't know AS3 and I don't have flash, but I found an online demo of an AS3 interpreter so I tested this code and it worked. It is not optimized and I sure as hell don't know any best practices, but you might want to give it a shot
Code: |
class GameConfig {
static var spriteDirections = 8;
static var slice = 360 / spriteDirections;
}
dynamic class Point2D {
static var radtodeg:Double = 180 / Math.PI;
var [x,y] = [0,0];
function Point2D(_x, _y){
this.x = _x; this.y = _y;
}
function delta(target):Point2D{
return new Point2D(target.x - this.x, target.y - this.y);
}
function toAngle():Double{
var angle = Math.atan2(this.x, this.y) * radtodeg;
return angle<0?angle+360:angle;
}
}
dynamic class Player {
var [position, facing, angle] =[new Point2D(0,0),0,0];
function Player(_x, _y){
this.position = new Point2D(_x, _y);
}
function face(target):Integer {
angle = this.position.delta(target.position).toAngle();
facing = Math.round(angle / GameConfig.slice) % GameConfig.spriteDirections;
return facing;
}
}
var player = new Player(100,100);
var target = new Player(110,0);
player.face(target);
Util.print(player.facing);
Util.print(player.angle);
|
http://eval.hurlant.com/demo <- I tested it here.
|
|
Back to top |
|
 |
|
Posted: Tue, 8th Apr 2014 12:35 Post subject: |
|
 |
Last edited by Interinactive on Tue, 5th Oct 2021 02:18; edited 1 time in total
|
|
Back to top |
|
 |
|
Posted: Tue, 8th Apr 2014 12:54 Post subject: |
|
 |
Oh, my last AS actually does spit out the direction with one function My offer with Skype still stands, we could go through the lines and classes one by one and I'm quite sure you'll get the setup real quick (even if you dislike the math) 
|
|
Back to top |
|
 |
Page 1 of 1 |
All times are GMT + 1 Hour |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB 2.0.8 © 2001, 2002 phpBB Group
|
|
 |
|