Jump to content

[Mod Development] Need help with prefab orientation

Recommended Posts

I'm working on a mod that places 10 prefabs in-a-row with respect to the camera orientation.  I don't want to simply use one prefab for North-South, a different one for East-West, and two more for the diagonals.  Doing it that way should work, but it would be cumbersome for the player to have four options in the structures tab for every type of wall (and some other stuff).


My strategy right now is using a custom prefab of a "ghost wall" which is basically a plain image of 10 stone wall silhouettes to show the player where the walls will be placed.  When the player puts the "ghost wall" prefab on the ground, the script removes it and sends the coordinates through an iteration to place 10 vanilla wall segments in a row at that location.


I thought this would be simple to implement, but I'm having major trouble with orienting the prefab based on the camera angle.  I've been looking through the game files, but I can't figure out what functions are going to give me the information needed for the script.


It seems to me that every prefab is simply placed at a location without a specific orientation! I'm getting frustrated at this point, so if anyone could point me in the right direction I'd really appreciate it.

Link to comment
Share on other sites

Srlsly? You set that picture on your account and you don't know how to do stuff according to your camera angle? Hah, just kidding ;)

But, that's right - Pig King throws gold at your camera angle, so just look into 'prefabs/pigking.lua' for some code :-)


Hope I helped :grin:


EDIT: The stuff that should interest you (from pigking.lua):

local down = TheCamera:GetDownVec()local angle = math.atan2(down.z, down.x) + (math.random()*60-30)*DEGREES
Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

  • Create New...