Page 1 of 1

player direction

Posted: Wed Aug 03, 2016 12:05 am
by lisa
Ok so I have been working on a game for a little and I get the cords and direction easy enough from memory, now to using those directions.

The way I see it I have 2 options to go with.
First is very similar to RoM in the way that you have 2 values and use the 2 values to work out which way you are pointing.
-1 0 North
0 1 West
1 0 South
0 -1 East

Second is another value which means direction which is very different for values but works in a similar way.
N -6627
W -6483
S 6627
E 6483
Values may be very slightly out as I am just looking at CE as I turn, the max values are -9270 which is NW and 9270 for SE with 0 for both NE and SW
There is another value which is very similar with 0 for NW and SE, SW 9270, NE -9270

So as far as calculations for direction goes which is easiest or best to use?

Re: player direction

Posted: Wed Aug 03, 2016 11:14 am
by beanybabe
I used a few game editors those numbers you are showing in ce look like they are from unreal.

here is a article that talks about some of the ways. http://www.aclockworkberry.com/world-co ... al-engine/

Re: player direction

Posted: Wed Aug 03, 2016 1:11 pm
by Administrator
I think I would probably go with the first option, as it seems to represent a unit vector more easily, which you can then convert to an angle (in radians) using sine & cosine, as we did in RoM.

Re: player direction

Posted: Thu Aug 04, 2016 1:06 am
by lisa
copy pasted a bit of code from RoM and turning ended up like this.

Code: Select all

				playerupdate()
				local angle = 0 --north
				local angleDif = angleDifference(angle, playerdirection);
				-- If more than X degrees off, correct before moving.
				local rotateStartTime = os.time();
				local turningDir = -1; -- 0 = left, 1 = right
				if( angleDif > math.rad(5) ) then
					if( os.difftime(os.time(), rotateStartTime) > 3.0 ) then
						-- Sometimes both left and right rotate get stuck down.
						-- Press them both to make sure they are fully released.
						keyboard.virtualRelease(win,key.VK_Q);
						keyboard.virtualRelease(win,key.VK_E);
						rotateStartTime = os.time();
					end

					if( angleDifference(angle, playerdirection + 0.01) < angleDif ) then
						-- rotate left
						keyboard.virtualRelease( win,key.VK_E );
						keyboard.virtualHold( win,key.VK_Q );
					else
						-- rotate right
						keyboard.virtualRelease(win,key.VK_Q);
						keyboard.virtualHold( win,key.VK_E );
					end
				else
					keyboard.virtualRelease(win,key.VK_Q);
					keyboard.virtualRelease(win,key.VK_E);
				end
Initial testing it is working pretty good, I'll tidy it up and add keys to my variables and such but it should do the job =)
No issues with calling virtualHold constantly, at the moment it's not checking if already held and so just keeps doing hold over and over again or should I add in checks for if held before doing Hold again ?