player direction

For any other game that doesn't have its own section.
Post Reply
Message
Author
User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

player direction

#1 Post by lisa » Wed Aug 03, 2016 12:05 am

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?
Remember no matter you do in life to always have a little fun while you are at it ;)

wiki here http://www.solarstrike.net/wiki/index.php?title=Manual

User avatar
beanybabe
Posts: 647
Joined: Wed Mar 06, 2013 1:27 am

Re: player direction

#2 Post by beanybabe » Wed Aug 03, 2016 11:14 am

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/

User avatar
Administrator
Site Admin
Posts: 5306
Joined: Sat Jan 05, 2008 4:21 pm

Re: player direction

#3 Post by Administrator » Wed Aug 03, 2016 1:11 pm

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.

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: player direction

#4 Post by lisa » Thu Aug 04, 2016 1:06 am

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 ?
Remember no matter you do in life to always have a little fun while you are at it ;)

wiki here http://www.solarstrike.net/wiki/index.php?title=Manual

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests