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

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

Re: Obstacles for 2D BF2 Level...

Postby [RDH]Zerted » Tue Jan 27, 2009 1:33 pm

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.

Jedi
User avatar
Posts: 1233
Joined: Wed Sep 12, 2007 3:13 pm

Re: Obstacles for 2D BF2 Level...

Postby Frisbeetarian » Tue Jan 27, 2009 9:05 pm

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?

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

Re: Obstacles for 2D BF2 Level...

Postby [RDH]Zerted » Tue Jan 27, 2009 11:24 pm

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.

Jedi
User avatar
Posts: 1233
Joined: Wed Sep 12, 2007 3:13 pm

Re: Obstacles for 2D BF2 Level...

Postby Frisbeetarian » Wed Jan 28, 2009 6:45 pm

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.

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

Re: Obstacles for 2D BF2 Level...

Postby [RDH]Zerted » Thu Jan 29, 2009 8:03 pm

Hidden/Spoiler:
Frisbeetarian wrote: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: Select all
CreateMatrix(-2.25, 0.0, 1.0, 0.0, 10.0, 4.0, -8.0, planetMatrix)
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.
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("")

Jedi
User avatar
Posts: 1233
Joined: Wed Sep 12, 2007 3:13 pm

Re: Obstacles for 2D BF2 Level...

Postby Frisbeetarian » Thu Jan 29, 2009 9:40 pm

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.

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

Re: Obstacles for 2D BF2 Level...

Postby [RDH]Zerted » Thu Jan 29, 2009 10:28 pm

@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:

Jedi
User avatar
Posts: 1233
Joined: Wed Sep 12, 2007 3:13 pm

Re: Obstacles for 2D BF2 Level...

Postby Frisbeetarian » Fri Jan 30, 2009 2:09 am

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 )

Droid Pilot Assassin
User avatar
Posts: 2086
Joined: Mon Feb 13, 2006 3:28 am

Re: Obstacles for 2D BF2 Level...

Postby Sky_216 » Fri Jan 30, 2009 8:52 am

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.'

Jedi
User avatar
Posts: 1233
Joined: Wed Sep 12, 2007 3:13 pm

Re: Obstacles for 2D BF2 Level...

Postby Frisbeetarian » Fri Jan 30, 2009 1:32 pm

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.

Droid Pilot Assassin
User avatar
Posts: 2086
Joined: Mon Feb 13, 2006 3:28 am

Re: Obstacles for 2D BF2 Level...

Postby Sky_216 » Fri Jan 30, 2009 3:21 pm

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"

Jedi
User avatar
Posts: 1233
Joined: Wed Sep 12, 2007 3:13 pm

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

Postby Frisbeetarian » Fri Jan 30, 2009 5:27 pm

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.

Droid Pilot Assassin
User avatar
Posts: 2086
Joined: Mon Feb 13, 2006 3:28 am

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

Postby Sky_216 » Fri Jan 30, 2009 5:48 pm

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.

Jedi
User avatar
Posts: 1233
Joined: Wed Sep 12, 2007 3:13 pm

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

Postby Frisbeetarian » Fri Jan 30, 2009 8:44 pm

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.

Jedi Admin
User avatar
Posts: 11025
Joined: Wed Sep 07, 2005 11:42 pm
Location: Indiana
Projects :: No Mod project currently.
Games I'm Playing :: Destiny
xbox live or psn: No gamertag set

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

Postby Teancum » Sun Feb 01, 2009 12:05 am

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.

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

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

Postby [RDH]Zerted » Sun Feb 01, 2009 12:36 am

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.

Jedi Admin
User avatar
Posts: 7420
Joined: Mon Aug 21, 2006 11:03 pm

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

Postby Maveritchell » Sun Feb 01, 2009 12:40 am

[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.

Jedi
User avatar
Posts: 1233
Joined: Wed Sep 12, 2007 3:13 pm

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

Postby Frisbeetarian » Sun Feb 01, 2009 3:40 am

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.

Jedi Admin
User avatar
Posts: 11025
Joined: Wed Sep 07, 2005 11:42 pm
Location: Indiana
Projects :: No Mod project currently.
Games I'm Playing :: Destiny
xbox live or psn: No gamertag set

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

Postby Teancum » Sun Feb 01, 2009 5:48 pm

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.

Previous

Return to SWBF2 Modding

Who is online

Users browsing this forum: No registered users and 1 guest