2D Level - Turning Fixed, Camera Placement Still An Issu

In this forum you will find and post information regarding the modding of Star Wars Battlefront 2. DO NOT POST MOD IDEAS/REQUESTS.

Moderator: Moderators

User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: Obstacles for 2D BF2 Level...

Post by [RDH]Zerted »

Skyhammer_216 wrote:...What is the player's 'matrix'
Its basically how the game represents where every entity is in the game. You can teleport any object to a matrix location. You can think of the matrix as a spawn point. Its just a point somewhere in the map with a certain direction (and maybe a speed).

There is a lua function that allows you to create a matrix (the Galactic Conquest scripts use it), but I've never fooled around with it. In theory, you use GetMatrix() on the player's unit. Then you take its result, change the facing value, then teleport the player to the new matrix. This will have the effect of exactly reversing the direction the player is facing.

It can be done if someone figures out how to understand the results of GetMatrix(). I'm thinking it might be a lua table, but I've really haven't tried to find out. You would have to get the result, then play around with its numbers to see what changes makes what change ingame. The Example Finder can show you all the places the game uses the matrix functions.

Basically, referencing any point in the map and saving data are the last two important lua things that remain unfinished (if thats wrong, what did I forget?). I believe both can be done, but I haven't had the time to look at them.
User avatar
Frisbeetarian
Jedi
Jedi
Posts: 1233
Joined: Wed Sep 12, 2007 3:13 pm

Re: Obstacles for 2D BF2 Level...

Post by Frisbeetarian »

Searching through the entire mod tools directory revealed no uses of GetMatrix.

Here are some examples to chew on of getting a matrix from ifs_freeform_main:

Code: Select all

local matrix = this.planetMatrix[planet][0]
SetEntityMatrix(fleetPtr, this.modelMatrix[next][team])
This threw me off initially because planetMatrix was not defined in the script. It is created in ifs_campaign_main script, but I'm not sure how that applies to GC. (It seems like though it's titled with campaign, the script would be used for GC, but it uses the if screen ifs_campaign_mission (created in ifs_campaign_data script), which only has the missions for the campaign.) Regardless, the ifs_campaign_main script gives a much better view of working with matrices in this excerpt.

Code: Select all

for _, mission in ipairs(ifs_campaign_mission) do
	local planet = mission.planet
	local planetMatrix = GetEntityMatrix(planet)
	this.planetMatrix[planet] = {}
	this.planetMatrix[planet][0] = planetMatrix
	this.planetMatrix[planet][1] = CreateMatrix(-2.25, 0.0, 1.0, 0.0, 10.0, 4.0, -8.0, planetMatrix)
	this.planetMatrix[planet][2] = CreateMatrix(2.25, 0.0, 1.0, 0.0, -10.0, 4.0, -8.0, planetMatrix)
	this.modelMatrix[planet] = {}
	this.modelMatrix[planet][1] = GetEntityMatrix(planet .. "_fleet1") or this.planetMatrix[planet][1]
	this.modelMatrix[planet][2] = GetEntityMatrix(planet .. "_fleet2") or this.planetMatrix[planet][2]
end
It also shows that the command is instead of GetMatrix, GetEntityMatrix.

P.S. Using the print command, where does it print to?
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: Obstacles for 2D BF2 Level...

Post by [RDH]Zerted »

Yes, those are the lines I was thinking of. Now we need to figure out the contents of planetMatrix and which numbers to change to move the entity around. Those lines deal with where to put the planets and space ships on the GC map. So take a screen shot of GC, mess with the numbers, take another screen shot, and compare the two images.

Print outputs to the debug log.
User avatar
Frisbeetarian
Jedi
Jedi
Posts: 1233
Joined: Wed Sep 12, 2007 3:13 pm

Re: Obstacles for 2D BF2 Level...

Post by Frisbeetarian »

I figured out my other questions, so here's my result (so far).

Code: Select all

print(this.planetMatrix[planet][0], "print test")
print(this.planetMatrix[planet][1], "print test")
this.planetMatrix[planet][0] = planetMatrix
this.planetMatrix[planet][1] = CreateMatrix(2.25, 0.0, 1.0, 0.0, -10.0, 4.0, -8.0, planetMatrix)
print(this.planetMatrix[planet][1], "print test")
This is what I put inside the CreateFleet function inside and after creating both a fleet for me and a fleet for the enemy at the same planet, this is the output I got, I can't make heads or tails of it.
userdata: 059CE698 print test
userdata: 059CE720 print test
userdata: 057A62D4 print test
nil print test
userdata: 057A62D4 print test
userdata: 059E3BE0 print test
On a side note, in reference to my previous post, I deleted the contents of ifs_campaign_main, and the GC still worked, which should mean that GC doesn't reference it.
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: Obstacles for 2D BF2 Level...

Post by [RDH]Zerted »

Hidden/Spoiler:
[quote="Frisbeetarian"]Working on these matrices solely in the confines of GC, I have noticed a few things. Based on the function CreateMatrix (which is only found in freeform_main and campaign_main) and looks as such:[code]CreateMatrix(-2.25, 0.0, 1.0, 0.0, 10.0, 4.0, -8.0, planetMatrix)[/code] I have found that the matrix at the end acts as a starting point for the seven values before hand. A change, both large and small, in the first four values caused no noticeable change to the relation of the ship to its original picture. The last three values cause translation in the positive direction for x,y,z respectively on a right handed axis with +x pointing left and +z pointing up (looking across the plain of the galaxy).

I have not figured out, however, how a matrix is made or even of how many elements it is composed. I'm pretty sure that the matrices are established in gal1.lvl (looking in it, I can see where the objects are established and their names printed to the debug log match the names inside the lvl).

It should also be noted that printing the matrix, while producing 8 hex digits, has no change in the first four every round, but between rounds, all but the first two change, even when no change is made to the shell.

P.S. You brought this up, and it interested me, so I'm just trying to keep you informed of what I've found. If you know this already, or if you don't really care, just tell me, and I'll keep it to myself. On the other hand, if you have something to add, please do, I would love to hear it. I don't really know where to go from here.

P.P.S. I PMed you since it was really just a dialogue between us two. If you think that I should post in the tread instead, that's fine with me.[/quote]
The matrix is some type of data structure, so simply printing it prints out its type and memory address. Just like you can't simply print out a table or function. It does print out some table/function info, but it doesn't tell you anything useful about the contents of that table/function.

So CreateMatrix() seems to generate a new matrix based off an existing one? If we can change one, then theres no need to build one from scratch. Try:

Code: Select all

local unit = GetCharacterUnit( player )
local unitLocation = GetEntityMatrix( unit )
local newUnitLocation = CreateMatrix(-2.25, 0.0, 1.0, 0.0, 10.0, 4.0, -8.0,  unitLocation)
SetEntityMatrix( unit, newUnitLocation )
print("Did the player move?", unit, unitLocation, newUnitLocation)
ShowMessageText("")
User avatar
Frisbeetarian
Jedi
Jedi
Posts: 1233
Joined: Wed Sep 12, 2007 3:13 pm

Re: Obstacles for 2D BF2 Level...

Post by Frisbeetarian »

That function works to set a new position for a unit, though I must amend my previous thoughts on what the numbers do. I have yet to figure out exactly what the first four numbers do, though at least one of the first or third affects rotation (maybe both, and I think it's in radians). The last three however act as coordinates to a vector that is added onto the (I'm guessing) input matrix. (The effect of this is that I'm moved to the left and forward by setting positive x and z coordinates respectively and I'm moved up by setting the y positive.) I also know that velocity is conserved on matrix changes (at least while changing the last three) and that movement happens before rotation.
Last edited by Frisbeetarian on Fri Jan 30, 2009 12:26 am, edited 1 time in total.
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: Obstacles for 2D BF2 Level...

Post by [RDH]Zerted »

@Skyhammer_216: So the answer to question 1 is when a player dispenses some temporary object, teleport the player to his matrix rotated 180 degrees or 1 radian (pie). You can use the above code as a template. You will need to add the event handling and change the CreateMatrix() numbers a bit.

Nice work :thumbs:
User avatar
Frisbeetarian
Jedi
Jedi
Posts: 1233
Joined: Wed Sep 12, 2007 3:13 pm

Re: Obstacles for 2D BF2 Level...

Post by Frisbeetarian »

Here are my results. I wouldn't stake my life on their accuracy, especially when combining rotation around multiple axes, but other than that I found no discrepancies.
CreateMatrix(float1, float2, float3, float4, float5, float6, float7, matrix)

- float1 rotation angle in radians around chosen axes or x axis if none chosen (
- float2 rotation around x axis if float2 ~= 0
- float3 rotation around y axis if float3 ~= 0
- float4 rotation around z axis if float4 ~= 0
- float5 translates unit on x axis
- float6 translates unit on y axis
- float7 translates unit on z axis
- matrix floats 1-7 all make their changes with matrix as their starting point

X axis is positive to character's left
Y axis is positive above character
Z axis is positive in front of character
translation units correspond with coordinate units in ZeroEditor
positive rotation follows right hand rule
For example, Skyhammer_216, your final code will be

Code: Select all

	local unit = GetCharacterUnit( player )
	local unitLocation = GetEntityMatrix( unit )
	local newUnitLocation = CreateMatrix(3.14, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0,  unitLocation)
	SetEntityMatrix( unit, newUnitLocation )
User avatar
Sky_216
Droid Pilot Assassin
Droid Pilot Assassin
Posts: 2086
Joined: Mon Feb 13, 2006 3:28 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

Re: Obstacles for 2D BF2 Level...

Post by Sky_216 »

Thanks heaps for your help guys, I'd pretty much given up on this idea until I checked what you guys wrote

I'm not a scripting genius, so I'm just wonderig, what should I nest the bit of code you gave me in?
The weapon I'll be using to switch directions is called '2dp_weap_inf_180.'
User avatar
Frisbeetarian
Jedi
Jedi
Posts: 1233
Joined: Wed Sep 12, 2007 3:13 pm

Re: Obstacles for 2D BF2 Level...

Post by Frisbeetarian »

Following what Zerted said, use code

Code: Select all

turn = OnCharacterDispensePowerup(
	function( player, powerup )
	local unit = GetCharacterUnit( player )
	local unitLocation = GetEntityMatrix( unit )
	local newUnitLocation = CreateMatrix( 3.14, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0,  unitLocation )
	SetEntityMatrix( unit, newUnitLocation )
	end
)
If you plan to use other dispensable weapons, you'll need to stick the body of the function inside an if statement that checks to only a specific powerup turns you around.
User avatar
Sky_216
Droid Pilot Assassin
Droid Pilot Assassin
Posts: 2086
Joined: Mon Feb 13, 2006 3:28 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

Re: Obstacles for 2D BF2 Level...

Post by Sky_216 »

Frisbeetarian wrote:Following what Zerted said, use code

Code: Select all

turn = OnCharacterDispensePowerup(
function( player, powerup )
local unit = GetCharacterUnit( player )
local unitLocation = GetEntityMatrix( unit )
local newUnitLocation = CreateMatrix( 3.14, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, unitLocation )
SetEntityMatrix( unit, newUnitLocation )
end
)
If you plan to use other dispensable weapons, you'll need to stick the body of the function inside an if statement that checks to only a specific powerup turns you around.
Works perfectly!!!
Thanks heaps guys.


Now, here's the other problem - getting the camera sorted to look at you from the side....

I'm assuming you use these values in some way???
CAMERASECTION = "STAND"
EyePointOffset = "0.0 1.8 0.0"
TrackCenter = "0.0 1.8 0.0
TrackOffset = "0.0 0.0 3.2"
TiltValue = "10.0"
User avatar
Frisbeetarian
Jedi
Jedi
Posts: 1233
Joined: Wed Sep 12, 2007 3:13 pm

Re: 2D Level - Turning Fixed, Camera Placement Still An Issu

Post by Frisbeetarian »

I can think of a way to do it creating a camera object, using MoveCameraToEntity, and adjusting the camera object's position based on unit movement using the matrix code from above and a timer.
User avatar
Sky_216
Droid Pilot Assassin
Droid Pilot Assassin
Posts: 2086
Joined: Mon Feb 13, 2006 3:28 am
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

Re: 2D Level - Turning Fixed, Camera Placement Still An Issu

Post by Sky_216 »

Frisbeetarian wrote:I can think of a way to do it creating a camera object, using MoveCameraToEntity, and adjusting the camera object's position based on unit movement using the matrix code from above and a timer.
Please continue.
User avatar
Frisbeetarian
Jedi
Jedi
Posts: 1233
Joined: Wed Sep 12, 2007 3:13 pm

Re: 2D Level - Turning Fixed, Camera Placement Still An Issu

Post by Frisbeetarian »

In theory, what I said should work. I'm working out the finer details as it is, and so far, I've gotten a unit to move along with the remote droid it deploys.
User avatar
Teancum
Jedi Admin
Jedi Admin
Posts: 11080
Joined: Wed Sep 07, 2005 11:42 pm
Projects :: No Mod project currently.
Games I'm Playing :: Destiny
xbox live or psn: No gamertag set
Location: Indiana

Re: 2D Level - Turning Fixed, Camera Placement Still An Issu

Post by Teancum »

If you're just going two directions just hard code two camera values and switch them on the fly in LUA based on your direction. No need for complexity.
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: 2D Level - Turning Fixed, Camera Placement Still An Issu

Post by [RDH]Zerted »

Frisbeetarian wrote:...creating a camera object, using MoveCameraToEntity, and adjusting the camera object's position based on unit movement using the matrix code from above and a timer.
I've never really messed around with the camera system. When you move the camera to an entity, does it lock onto the entity or does it just sit there and let the entity walk out of sight? Since you mentioned the timer, I'll assume it doesn't lock on? Moving the camera to the player every few seconds might make the game feel jumpy.

So there is no way to simply adjust the camera angles on a unit? Isn't there a way to adjust the camera angles for a vehicles and controllables? If both are true, then might it be easier/more user firendly to have the player control a remote controllable or be in a vehicle the entire map.
User avatar
Maveritchell
Jedi Admin
Jedi Admin
Posts: 7366
Joined: Mon Aug 21, 2006 11:03 pm

Re: 2D Level - Turning Fixed, Camera Placement Still An Issu

Post by Maveritchell »

[RDH]Zerted wrote:So there is no way to simply adjust the camera angles on a unit? Isn't there a way to adjust the camera angles for a vehicles and controllables? If both are true, then might it be easier/more user firendly to have the player control a remote controllable or be in a vehicle the entire map.
You can; camera rotation can't be controlled, I believe (which is the crux of the issue) - camera position can be moved along the axes. You might do a large offset to the rear and one side - it would still be to the rear of a unit, and the perception of the third dimension would still be there, though.
User avatar
Frisbeetarian
Jedi
Jedi
Posts: 1233
Joined: Wed Sep 12, 2007 3:13 pm

Re: 2D Level - Turning Fixed, Camera Placement Still An Issu

Post by Frisbeetarian »

Teancum wrote:just hard code two camera values
And how would you do that? From your own work, the only Lua commands relating to the camera are
Teancum wrote:SnapMapCamera
GetMapCameraZoom
SetMapCameraZoom
SetMapCameraPitch
SetMapCameraOffset
SetMapCameraPosition
GetMapCameraPosition
MoveCameraToEntity
SetCameraPosition
SetCameraRotation
AddCameraShot
I know what the Zoom does, and I can't see how that would work at all for the map, and I have a feeling that the position ones do something similar and thus also can't be used (I only did a couple tests with those, so it's definitely not conclusive). I'm hoping that MoveCameraToEntity will be what I need, since it seems to be used that way in the shipped scripts.
[RDH]Zerted wrote:I've never really messed around with the camera system. When you move the camera to an entity, does it lock onto the entity or does it just sit there and let the entity walk out of sight? Since you mentioned the timer, I'll assume it doesn't lock on? Moving the camera to the player every few seconds might make the game feel jumpy.
I've taken a break for a couple days, since I spent a lot of time on this and I've gotten behind in homework, so I can't answer how or if MoveCameraToEntity works, but like I said before, I moved a unit around with its remote droid using the SetEntityMatrix, and that worked just fine. The only problem I can foresee with this is that it requires constant Lua work as the timer runs every hundredth of a second to reset the matrix to make the motion fluid. If you know of a way to access the frame speed, I can just use that for the timer amount, since a hundredth of a second is much shorter than I actually need.
User avatar
Teancum
Jedi Admin
Jedi Admin
Posts: 11080
Joined: Wed Sep 07, 2005 11:42 pm
Projects :: No Mod project currently.
Games I'm Playing :: Destiny
xbox live or psn: No gamertag set
Location: Indiana

Re: 2D Level - Turning Fixed, Camera Placement Still An Issu

Post by Teancum »

Frisbeetarian wrote:
Teancum wrote:just hard code two camera values
And how would you do that?
Simple, store the values as strings, then use SetProperty or one of its "brothers". Easy enough.
Post Reply