[SOLVED] Camera X, Y, Z query

The formulas I saw for 3D trilateration were pretty complicated at first. Your idea of putting volume and spawning ship directly on the x, y, and z axis helped to greatly simplify them I think.

I think that’s exactly what did it. I’ll admit it was unintentional though.

Sometimes coincidences give great results ^^

1 Like

Okay, here is what I have found practical to use. This, once set up, can allow me to script quickly the exact location I want the camera to be with very little trial and error. Trial and error in the old way (just modifying the X, Y, X coordinates) took hours trying to script a simple scene.

I added everything @radar3301 has provided above.

I then added some code myself (disclaimer, I am not a LUA developer)
In \HomeworldRM\B8MissionMOD\leveldata\campaign\rr_oemb\m28_Return_gehenna.lua

Add Function:

function cheat_i()
print(“Camera Position”)
local leaderPosition = SobGroup_GetCentrePosition(“HumanPlayerSOB”)
print(“leaderPosition = {”…leaderPosition[1]…", “…leaderPosition[2]…”, “…leaderPosition[3]…”},")
local pos = Camera_GetPosition();
print(pos[“X”], pos[“Y”], pos[“Z”])
end

And in the function: function Rule_Init()

UI_BindKeyEvent( IKEY, ‘cheat_i’ )

Summary

Basically, in making scenes, I use the AddCamera to control where the player is looking. AddCamera requires two sets of XYZ coordinates, first set being where the camera will look and the second set of the base point of the camera.
e.g.

addCamera(“camera1”, {0.000000, 0.000000, 0.000000}, {-252.000000, 1548.000000, 5791.000000})

In game, I select an object (ship, asteroid, etc). I move the screen to position how I want the player to see it. then I press “i”.

Using the code in my example:

local leaderPosition = SobGroup_GetCentrePosition(“HumanPlayerSOB”)
print(“leaderPosition = {”…leaderPosition[1]…", “…leaderPosition[2]…”, “…leaderPosition[3]…”},")

Returns this in the HwRM.log:

leaderPosition = {720.3656005859375, 828.7918090820313, 968.1722412109375},

Since in most scenes the player is going to look at something, I use the “something” to provide the coordinates of WHERE the player is looking.

Then using @radar3301 code, which is activated by me calling;

local pos = Camera_GetPosition();
print(pos[“X”], pos[“Y”], pos[“Z”])

Returns this in the HwRM.log:

-252.1182701686859

1543.764143411255

5792.635323712289

This is the BASE POINT.

I copy those two prints from the log into the addCamera in my m28_Return_gehenna.level file. And I now have a camera starting point that will start near exactly where I hit “i” in my game.

WISHLIST to make this even easier.
My first PRINT statement is a near perfect copy-paste from log to level file. I only have to trim the extra digits past 5. However @radar3301 function returned values printed are on 3 lines and I have to massage the data more to get into the AddCamera. I have been trying to do string manipulation in order to automatically scrape the log and write the values in the correct syntax for an easier copy-paste but, and with my limited LUA knowledge, I have not been successful. Print looks to be more a simple function to view results quickly. I can do this outside of LUA with C#, PowerShell, etc but that requires using another tool to do something that may be able to be inherent in this function on its own?

Basically it would be nice to turn this:

Camera Position
leaderPosition = {720.3656005859375, 828.7918090820313, 968.1722412109375},
-252.1182701686859

1543.764143411255

5792.635323712289

into this:

addCamera(“camera1”, {720.365600, 828.79180, 968.17224}, {-252.118270, 1543.764143, 5792.635323})

It is a small thing… but as a programmer I am always looking for ways to automate to make things easier. :slight_smile:

@BitVenom I am also curious, the camActions you showed us in this post:

Is it possible to use that current functionality to control camera movements for a Mission Map? Or is CamAction just a tool for making videos?

Currently in my attempts to make a mission map, when I want to make a “scene” for the player using the in game units I just use normal HW2 scripting reference to script in lua.

local pos = Camera_GetPosition()
print(pos["X"], pos["Y"], pos["Z"])

should be

local pos = Camera_GetPosition()
print("campos = {" .. pos.X .. ", " .. pos.Y .. ", " .. pos.Z .. "}")

to get it to print on one line.

Also, not sure if the format library function is available in GameRules, but if it is (duh, it is. It’s used in the ATI_AddString function in camerautils.lua [facepalm]), this will help you immensely:

local pos = Camera_GetPosition()
print(format("campos = {%0.5d, %0.5d, %0.5d}", pos.X, pos.Y, pos.Z))

(And yes, you can reference named table keys like that :slight_smile: ).


EDIT:

Even better:

local dst = SobGroup_GetCentrePosition("HumanPlayerSOB")
local src = Camera_GetPosition()
print("addCamera(\"camera1\", " .. format("{%f, %f, %f}, {%f, %f, %f}", dst[1], dst[2], dst[3], src.X, src.Y, src.Z) .. ")\n")

EDIT:
Fixed print code.

4 Likes

I didn’t know you could use format() with several variables in one call, that’s good to know !

That’s the whole point of format. :slight_smile:

I fixed the addCamera print line above, reposted here:

local dst = SobGroup_GetCentrePosition("HumanPlayerSOB")
local src = Camera_GetPosition()
print("addCamera(\"camera1\", " .. format("{%f, %f, %f}, {%f, %f, %f}", dst[1], dst[2], dst[3], src.X, src.Y, src.Z) .. ")\n")
1 Like

Ship sway actually doesn’t affect the calculations (even though ships do sway). I printed out the values of the positions of the probes used as “anchors”, and they don’t change. I’m now of the opinion that the camera sways slightly. I did a quick test using a KeyBind (yes, they work, even while paused), and without moving the camera, got several differing values (I think it’s an “elastic” camera). Again though:

Ran into a problem trying to get my invisible ship to work, which did work in my previous mod. I feel the error message is telling me what to do; however, i do not work with ships much and do not want to risk mucking things up.

here is the error message, “Error in Ship/Missile:‘HGN_INVISIBLETARGET’: The Thruster brake time needs to be smaller than the acceleration time!”

What value does I need to tweak in the ship? Here is my ship:

Blockquote
NewShipType = StartShipConfig()
NewShipType.displayedName=“Target”
NewShipType.sobDescription=“Target Point”
NewShipType.maxhealth=getShipNum(NewShipType, “maxhealth”, 90000)
NewShipType.regentime=0
NewShipType.minRegenTime=0
NewShipType.sideArmourDamage = getShipNum(NewShipType, “sideArmourDamage”, 1.0)
NewShipType.rearArmourDamage = getShipNum(NewShipType, “rearArmourDamage”, 1.0)
setTacticsMults(NewShipType, “MAXSPEED”, 1.0, 1.10, 1.0)
setTacticsMults(NewShipType, “ENGINEACCEL”, 1.20, 0.80, 1.0)
setTacticsMults(NewShipType, “ENGINEBRAKE”, 1.0, 1.0, 1.0)
setTacticsMults(NewShipType, “THRUSTER”, 1.0, 1.0, 1.0)
setTacticsMults(NewShipType, “THRUSTERACCEL”, 1.20, 0.80, 1.0)
setTacticsMults(NewShipType, “THRUSTERBRAKE”, 1.0, 1.0, 1.0)
setTacticsMults(NewShipType, “ROTATION”, 1.0, 1.10, 1.0)
setTacticsMults(NewShipType, “ROTATIONACCEL”, 1.0, 1.10, 1.0)
setTacticsMults(NewShipType, “ROTATIONBRAKE”, 1.0, 1.0, 1.0)
setTacticsMults(NewShipType, “WEAPONACCURACY”, 1.0, 1.0, 1.0)
setTacticsMults(NewShipType, “WEAPONDAMAGE”, 1.20, 1.0, 1.0)
setTacticsMults(NewShipType, “BULLETSPEED”, 1.15, 1.0, 1.0)
setTacticsMults(NewShipType, “DAMAGEAPPLIED”, 1.10, 0.90, 1.0)
setTacticsMults(NewShipType, “FIRERATE”, 1.0, 1.25, 1.0)
setSpeedvsAccuracyApplied(NewShipType, 100.0, 5.0, 250, 1.0, 409, 1.0, 563, 0.90)
NewShipType.isTransferable=1
NewShipType.SquadronSize=getShipNum(NewShipType, “SquadronSize”, 1)
NewShipType.buildBatch=getShipNum(NewShipType, “buildBatch”, 1)
NewShipType.formationSpacing=30
NewShipType.batchFormation=“Batch_delta”
NewShipType.defaultROE=“Defensive”
NewShipType.defaultStance=“Aggressive”
NewShipType.holdSlots=2
NewShipType.mass=10
NewShipType.collisionMultiplier=1
NewShipType.thrusterMaxSpeed=1
NewShipType.mainEngineMaxSpeed=1
NewShipType.rotationMaxSpeed=1
NewShipType.thrusterAccelTime=1
NewShipType.thrusterBrakeTime=2
NewShipType.mainEngineAccelTime=1
NewShipType.mainEngineBrakeTime=2
NewShipType.rotationAccelTime=0.5
NewShipType.rotationBrakeTime=0.3
NewShipType.thrusterUsage=0.25
NewShipType.accelerationAngle=30
NewShipType.mirrorAngle=30
NewShipType.secondaryTurnAngle=90
NewShipType.maxBankingAmount=85
NewShipType.descendPitch=0
NewShipType.goalReachEpsilon=5
NewShipType.slideMoveRange=0
NewShipType.controllerType=“Ship”
NewShipType.tumbleStaticX=10
NewShipType.tumbleStaticY=20
NewShipType.tumbleStaticZ=5
NewShipType.tumbleDynamicX=100
NewShipType.tumbleDynamicY=200
NewShipType.tumbleDynamicZ=50
NewShipType.tumbleSpecialDynamicX=600
NewShipType.tumbleSpecialDynamicY=800
NewShipType.tumbleSpecialDynamicZ=500
NewShipType.relativeMoveFactor=6
NewShipType.swayUpdateTime=2
NewShipType.swayOffsetRandomX=10
NewShipType.swayOffsetRandomY=10
NewShipType.swayOffsetRandomZ=10
NewShipType.swayBobbingFactor=0.05
NewShipType.swayRotateFactor=0.1
NewShipType.dustCloudDamageTime=100
NewShipType.nebulaDamageTime=20
NewShipType.MinimalFamilyToFindPathAround=“SuperCap”
NewShipType.mirrorAboveManeuver=“ImmelMann_speedy, OneEightyDegRightTurn, OneEightyDegLeftTurn, ImmelMann_speedy, ImmelMann_speedy, ImmelMann_speedy”
NewShipType.mirrorBelowManeuver=“Split_S_speedy, OneEightyDegRightTurn, OneEightyDegLeftTurn, Split_S_speedy, Split_S_speedy, Split_S_speedy”
NewShipType.specialTurnLeftManeuver=“NinetyDegLeftTurn, None, None”
NewShipType.specialTurnRightManeuver=“NinetyDegRightTurn, None, None”
NewShipType.BuildFamily=“SuperCap_Hgn”
NewShipType.AttackFamily=“BigCapitalShip”
NewShipType.DockFamily=“Carrier”
NewShipType.AvoidanceFamily=“SuperCap”
NewShipType.DisplayFamily=“Capital”
NewShipType.AutoFormationFamily=“CapShip”
NewShipType.CollisionFamily=“Small”
NewShipType.ArmourFamily=getShipStr(NewShipType, “ArmourFamily”, “Unarmoured”)
setSupplyValue(NewShipType, “Capital”, 1.0)
setSupplyValue(NewShipType, “Carrier”, 1.0)
NewShipType.fighterValue=1
NewShipType.corvetteValue=0
NewShipType.frigateValue=0
NewShipType.neutralValue=0
NewShipType.antiFighterValue=0
NewShipType.antiCorvetteValue=0
NewShipType.antiFrigateValue=0
NewShipType.totalValue=1
NewShipType.buildCost=300
NewShipType.buildTime=20
NewShipType.buildPriorityOrder=10
NewShipType.retaliationRange=4800
NewShipType.retaliationDistanceFromGoal=160
NewShipType.visualRange=1500
NewShipType.prmSensorRange=9000
NewShipType.secSensorRange=11000
NewShipType.detectionStrength=1
NewShipType.TOScale=1
NewShipType.TODistanceFade0=7000
NewShipType.TODistanceDisappear0=5000
NewShipType.TODistanceFade1=2500
NewShipType.TODistanceDisappear1=2000
NewShipType.TODistanceFade2=12000
NewShipType.TODistanceDisappear2=35000
NewShipType.TOGroupScale=1
NewShipType.TOGroupMergeSize=0
NewShipType.mouseOverMinFadeSize=0.045
NewShipType.mouseOverMaxFadeSize=0.1
NewShipType.healthBarStyle=0
NewShipType.nlips=0.0008
NewShipType.nlipsRange=6000
NewShipType.nlipsFar=0.0003
NewShipType.nlipsFarRange=10000
NewShipType.SMRepresentation=“HardDot”
NewShipType.meshRenderLimit=11000
NewShipType.dotRenderLimit=10
NewShipType.visibleInSecondary=0
NewShipType.minLOD=0.25
NewShipType.goblinsStartFade=210
NewShipType.goblinsOff=210
–NewShipType.upLOD=700
–NewShipType.downLOD=500
NewShipType.minimumZoomFactor=0.68
NewShipType.selectionLimit=150000
NewShipType.preciseATILimit=0
NewShipType.selectionPriority=75
NewShipType.militaryUnit=1
addAbility(NewShipType,“MoveCommand”,1,0);
addAbility(NewShipType,“CanDock”,1,1);
NewShipType.dockTimeBetweenTwoFormations=0.5
NewShipType.dockTimeBeforeStart=0.5
NewShipType.dockNrOfShipsInDockFormation=1
NewShipType.dockFormation=“dockline”
NewShipType.queueFormation=“n_delta”
NewShipType.ignoreRaceWhenDocking=0
addAbility(NewShipType,“CanLaunch”);
addAbility(NewShipType, “HyperspaceInhibitorAbility”, 1, 12000);
NewShipType.launchTimeBetweenTwoFormations=0.5
NewShipType.launchTimeBeforeStart=1.5
NewShipType.launchNrOfShipsInDockFormation=1
NewShipType.launchFormation=“n_delta”
addAbility(NewShipType,“ParadeCommand”,1);
addAbility(NewShipType,“WaypointMove”);
addAbility(NewShipType,“CanAttack”,1,2,1,0,0.35,1,“Fighter, Fighter_hw1, Corvette, Corvette_hw1, Frigate, SmallCapitalShip, BigCapitalShip, Mothership”,“FlyBy_Interceptor_vs_Frigate”,
{Fighter=“Fighter_vs_Fighter”},
{Fighter_hw1=“Fighter_vs_Fighter”},
{Corvette=“Fighter_vs_Corvette”},
{Corvette_hw1=“Fighter_vs_Corvette”},
{Frigate=“Fighter_vs_Frigate”},
{SubSystem=“TopAttack_Interceptor_vs_Subsystem”},
{SmallCapitalShip=“Fighter_vs_CapShip”},
{BigCapitalShip=“Fighter_vs_CapShip”},
{Mothership=“Fighter_vs_Mothership”},
{ResourceLarge=“Fighter_vs_ResourceLarge”});
addAbility(NewShipType,“GuardCommand”,1,3000,500);
addAbility(NewShipType,“HyperspaceViaGateCommand”,1,3,1,0.3);
addAbility(NewShipType,“SensorPing”,0,1,10,2.5);
addAbility(NewShipType,“SpecialAttack”,0,“EMP”);
addAbility(NewShipType,“RetireAbility”,1,0);
LoadModel(NewShipType,1);
–StartShipWeaponConfig(NewShipType,“Hgn_Peashooter”,“Weapon_Autogun”,“Weapon_Autogun”);
–StartShipWeaponConfig(NewShipType,“Hgn_SmallEMP”,“Weapon_Autogun”,“Fire”);
NewShipType.battleScarCoverage=0
NewShipType.sobDieTime=2
NewShipType.sobSpecialDieTime=2
NewShipType.specialDeathSpeed=40
NewShipType.chanceOfSpecialDeath=0.5
NewShipType.deadSobFadeTime=1
–setEngineTrail(NewShipType,0,5,“trail_ribbon.tga”,0.001,0.5,0.025,8);
–setEngineBurn(NewShipType,15,0.5,1,15,0,0.7,0.1,25);
loadShipPatchList(NewShipType,“data:sound/sfx/ship/Hiigaran/Fighter/”,0,“HScoutEng”,"");
addShield(NewShipType,“EMP”,100,20);
NewShipType.minFalloffDamageDist=15
NewShipType.maxFalloffDamageDist=153
NewShipType.maxFalloffScuttleDamageDist=15
6
NewShipType.explosiveScuttleDamageOnDeath=15
NewShipType.maxFalloffForce=500*10
NewShipType.explosiveDamageOnDeath=275
NewShipType.radiusDamageEvadeMod=1.1
NewShipType.hideNormalAttackUICooldown=1
NewShipType.agileFlight=1
NewShipType.homingDistance=2000
NewShipType.homingDelay=0.5
NewShipType.strikeGroupSpeed=5000
NewShipType.canSurround=0

Blockquote

Problem might be here. I don’t know what exactly the numbers represent however.

setTacticsMults(NewShipType, “THRUSTERACCEL”, 1.20, 0.80, 1.0)
setTacticsMults(NewShipType, “THRUSTERBRAKE”, 1.0, 1.0, 1.0)

That’s it, thrusterBrakeTime needs to be smaller than thrusterAccelTime

1 Like

I suppose otherwise your ship might end up going backwards…