Register for your free account! | Forgot your password?

You last visited: Today at 22:45

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[Release] Direction Sectors

Discussion on [Release] Direction Sectors within the CO2 PServer Guides & Releases forum part of the CO2 Private Server category.

Reply
 
Old   #1
 
Spirited's Avatar
 
elite*gold: 12
Join Date: Jul 2011
Posts: 8,283
Received Thanks: 4,192
[Release] Direction Sectors

Hey everyone.

So, it turns out that when you jump... you change directions. It's ok if people see you jump... but for people just walking into the screen, all they see is your old, predefined direction from before the jump. Firstly, here's a direction diagram:



Based on that, you can probably imagine that when you jump, you face in the direction of whichever arrowhead you're closest to. Here's the formula I developed that can be used to find that direction:

Code:
public const double RADIAN_TO_DEGREE = 57.295779513082323;

        /// <summary>Find the direction of a character based on two points.</summary>
        /// <param name="x1">The X Coordinate at Point 1.</param>
        /// <param name="y1">The Y Coordinate at Point 1.</param>
        /// <param name="x2">The X Coordinate at Point 2.</param>
        /// <param name="y2">The Y Coordinate at Point 2.</param>
        /// Developed by Spirited Fang - 2/18/2012
        public static byte GetDirectionSector(ushort x1, ushort y1, ushort x2, ushort y2)
        {
            double angle = (Math.Atan2(y1 - y2, x1 - x2) * RADIAN_TO_DEGREE) - 67.5;
            if (angle < 0)
                angle += 360;
            return (byte)(angle / 45);
        }
EDIT: Updated formula:

It's a minor detail, but you know - I'm into those minor details.

Sincerely,
Spirited Fang
Spirited is offline  
Thanks
4 Users
Old 02/19/2012, 01:32   #2
 
InfamousNoone's Avatar
 
elite*gold: 20
Join Date: Jan 2008
Posts: 2,012
Received Thanks: 2,885
Why not just use the standard implementation from the EO source?
It involves having to introduce doubles into the algorithm, and it avoids using any trigonometric functions.

edit:
nvm it appears that the EO function wasn't intended to be used in a system of any 2 (x,y) coordinate pairs to obtain the direction.
InfamousNoone is offline  
Old 02/19/2012, 01:39   #3
 
Spirited's Avatar
 
elite*gold: 12
Join Date: Jul 2011
Posts: 8,283
Received Thanks: 4,192
Quote:
Originally Posted by InfamousNoone View Post
Why not just use the standard implementation from the EO source?
It involves having to introduce doubles into the algorithm, and it avoids using any trigonometric functions.
Right! I keep forgetting that I can use EO as a reference. I'm not very familiar with it yet, but I'll look through it and see what I can find. Thanks Roy.

Edit: I was just going to comment on your edit, it doesn't seem like it. Direction is sent in EO's packet... but it's not in CO's. Maybe it's a structure issue with their recent changes with 10010. When you jump, it defaults your direction to 0 (in real co).
Spirited is offline  
Old 02/20/2012, 16:24   #4
 
nTL3fTy's Avatar
 
elite*gold: 0
Join Date: Jun 2005
Posts: 692
Received Thanks: 353
Quote:
Originally Posted by InfamousNoone View Post
Why not just use the standard implementation from the EO source?
It involves having to introduce doubles into the algorithm, and it avoids using any trigonometric functions.

edit:
nvm it appears that the EO function wasn't intended to be used in a system of any 2 (x,y) coordinate pairs to obtain the direction.
Code:
int CGameMap::GetDirection(int x0,int y0,int x1,int y1)
{
	int Dir;
	
	long Tan[4]	={-241,-41,41,241};
	long DeltaX	=x1-x0;
	long DeltaY	=y1-y0;
	
	if(DeltaX==0)
	{
		if(DeltaY>0)
			Dir	=0;
		else
			Dir	=4;
	}
	else if(DeltaY==0)
	{
		if(DeltaX>0)
			Dir	=6;
		else
			Dir	=2;
	}
	else
	{
		int Flag=abs(DeltaX)/DeltaX;
		
		DeltaY	*=(100*Flag);
		int i;
		for(i=0;i<4;i++)
			Tan[i]	*=abs(DeltaX);
		
		for(i=0;i<3;i++)
			if(DeltaY>=Tan[i] && DeltaY<Tan[i+1])
				break;
			
			//** note :
			//   i=0    ------- -241 -- -41
			//   i=1    ------- -41  --  41
			//   i=2    -------  41  -- 241
			//   i=3    -------  241 -- -241
			
			DeltaX=x1-x0;
			DeltaY=y1-y0;
			
			if(DeltaX>0)
			{
				if(i==0)			Dir	=5;
				else if(i==1)		Dir	=6;
				else if(i==2)		Dir	=7;
				else if(i==3)
				{
					if(DeltaY>0)	Dir	=0;
					else			Dir	=4;
				}
			}
			else
			{
				if(i==0)			Dir	=1;
				else if(i==1)		Dir	=2;
				else if(i==2)		Dir	=3;
				else if(i==3)
				{
					if(DeltaY>0)	Dir	=0;
					else			Dir	=4;
				}
			}
	}
	
	Dir	=(Dir+7)%8;
	return Dir;
}
nTL3fTy is offline  
Old 02/20/2012, 16:28   #5


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,126
Received Thanks: 2,518
@nTL3fTy - Yeah your right that is a horrible way of doing it...
Korvacs is offline  
Old 02/27/2012, 04:12   #6
 
elite*gold: 0
Join Date: Jan 2012
Posts: 76
Received Thanks: 11
Quote:
Originally Posted by Korvacs View Post
@nTL3fTy - Yeah your right that is a horrible way of doing it...
since you resigned from mod you've become a little critical haha.. i like it
unrrrreaL is offline  
Old 02/27/2012, 16:07   #7
 
elite*gold: 0
Join Date: Feb 2009
Posts: 920
Received Thanks: 3,514
And what happens if you jump and SS/FB in a direction a different direction than the one you are jumping to? your char should be facing where your SS/FB is going or supposed to be if you had low stam?
minor details
m7mdxlife is offline  
Old 02/27/2012, 16:09   #8


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,126
Received Thanks: 2,518
Quote:
Originally Posted by m7mdxlife View Post
And what happens if you jump and SS/FB in a direction a different direction than the one you are jumping to? your char should be facing where your SS/FB is going or supposed to be if you had low stam?
minor details
Since the attack packet is handled after the jump packet, the attack packets direction would override the change made by the jump packet.

So this would work as intended.
Korvacs is offline  
Thanks
2 Users
Old 01/13/2013, 07:13   #9
 
Spirited's Avatar
 
elite*gold: 12
Join Date: Jul 2011
Posts: 8,283
Received Thanks: 4,192
The above formula isn't correct in some cases.
Here's the updated formula:

Code:
        /// <summary> This function returns the direction for a jump or attack. </summary>
        /// <param name="x1">The x coordinate of the destination point.</param>
        /// <param name="y1">The y coordinate of the destination point.</param>
        /// <param name="x2">The x coordinate of the reference point.</param>
        /// <param name="y2">The y coordinate of the reference point.</param>
        public static byte GetDirectionSector(ushort x1, ushort y1, ushort x2, ushort y2)
        {
            double angle = GetAngle(x1, y1, x2, y2);
            byte direction = (byte)Math.Round(angle / 45.0);
            return (byte)(direction == 8 ? 0 : direction);
        }

        /// <summary> This function returns the angle for a jump or attack. </summary>
        /// <param name="x1">The x coordinate of the destination point.</param>
        /// <param name="y1">The y coordinate of the destination point.</param>
        /// <param name="x2">The x coordinate of the reference point.</param>
        /// <param name="y2">The y coordinate of the reference point.</param>
        public static double GetAngle(double x1, double y1, double x2, double y2)
        {
            // Declare and initialize local variables:
            double angle = (Math.Atan2(y2 - y1, x2 - x1) * RADIAN_TO_DEGREE) + 90;
            return angle < 0 ? 270 + (90 - Math.Abs(angle)) : angle;
        }
Spirited is offline  
Thanks
3 Users
Reply


Similar Threads Similar Threads
NPC Direction
04/12/2011 - CO2 Private Server - 8 Replies
The picture says everything related to my problem. http://i55.tinypic.com/2ylp5w0.png
[Help]NPC Direction
07/02/2010 - CO2 Private Server - 5 Replies
In my 5165 source all the NPCs I added seem to be facing the same way. This has always happened since I started with P servers. Anyone know how to change their direction? I know Changing the number for direction doesn't do anything. Edit: Does everyone have this same issue? Oo
[Release] CoEmu (v2) NPCSpawn Direction fix.
11/25/2009 - CO2 PServer Guides & Releases - 0 Replies
Note: As usual, I have not tested this on CoEmu, but It works on my server, however it's a little bit different, but this should do the same thing. And also, this is a very small edit, this might not be the correct way to fix it, but it works, so I'm not going to think about it any longer. Okay this is all you have to do, in the GameServer, open the Folder "Packets" than open the file named "SpawnNPC.cs". Edit the complete (static) byte with this public static byte SpawnNPC(int Type,...
Learning..little direction plz
06/17/2009 - Dekaron - 0 Replies
got the unpacker,ran it, have the data file, now what do i do to get it to run like an .exe so i can select it with the GG killer launcher?
Need a direction
03/30/2006 - Tutorials - 2 Replies
i just need to be pointed to the right direction. what i want to do is make some macros for an online game i play, conquer online 2.0. i will give a discription of a macro i have which is the type of macros i want to make, in this macro you select a pixel on you health and this macro keeps checking that pixle to see if it is gone and when it is gone it presses the FKey that your health pots are in but this macro dosent take over your comp so you can play the game. i've been looking on google...



All times are GMT +1. The time now is 22:48.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.