Difference between revisions of "User:DavidJCobb/Rotation Library Tutorial"
imported>DavidJCobb (Done for now!) |
imported>DavidJCobb m (→Notes: w00t) |
||
Line 95: | Line 95: | ||
* Keeping a Light anchored to a light source (e.g. wall sconce) that can be moved at run-time | * Keeping a Light anchored to a light source (e.g. wall sconce) that can be moved at run-time | ||
* Repositioning the invisible DummyBookMarkers in a bookshelf, when moving the bookshelf at run-time | * Repositioning the invisible DummyBookMarkers in a bookshelf, when moving the bookshelf at run-time | ||
** I don't know if you can spawn and move trigger zones at run-time. If so, then with minimal work, it should be possible to incorporate bookshelves in home decoration mods! |
Latest revision as of 01:10, 24 August 2014
This tutorial talks you through setting up a basic demo of my rotation library.
We're going to create a Dibella Statue and a Dragon Priest Mask, and add some script code to keep the mask anchored to the statue's face. Additionally, we'll make the statue rotate randomly whenever it's activated, so that we can test several cases without needing to jump in and out of the Creation Kit.
Setting up a basic test[edit | edit source]
Creating our test object[edit | edit source]
In the Object Window, filter to Activators. Right-click in the list pane and select "New." Fill out the dialog box as shown below:
- Name
- Orientation Demo
- Model
- Clutter\Statues\StatueDibella.nif
- Activate Text
- Perform Random Test
- Obstacle
- Checked.
- Ignored by Sandbox
- Checked.
Now, add the following script to it:
Scriptname CobbOrientationTest extends ObjectReference Import CobbLibraryRotations Import Utility ; ; These arrays define the position and rotation of the child object RELATIVE ; to this object. These would be the child's position and rotation if this ; object were placed at (0, 0, 0) and set to rotation (0, 0, 0). ; Float[] Property pfPositionOffset Auto Float[] Property pfRotationOffset Auto ; ; This is the object that we'll be placing. ; ObjectReference Property pkChildObject = None Auto Event OnInit() UpdateChildPosition() EndEvent Event OnActivate(ObjectReference akActionRef) RunTest() EndEvent Function RunTest() {Randomize this object's rotation, and then reposition and rotate the child object to match it.} SetAngle( RandomInt(0, 359) as float, RandomInt(0, 359) as float, RandomInt(0, 359) as float ) UpdateChildPosition() EndFunction Function UpdateChildPosition() {Disable physics on the child object, and then position and rotate it to keep it in line with this object.} If pkChildObject pkChildObject.SetMotionType(4) MoveObjectRelativeToObject(pkChildObject, Self, pfPositionOffset, pfRotationOffset) EndIf EndFunction
Finishing up[edit | edit source]
Now go to any cell (or make your own) and add the new statue to it; place the statue at (0, 0, 0) and do not rotate it. Then, add a Dragon Priest Mask to the cell, and position and rotate it so that it rests on top of the statue's face. Write down the mask's coordinates and rotation.
Edit the base activator's script properties. Set pfPositionOffset to an array containing the mask's coordinates; set pfRotationOffset to an array containing the mask's rotation. Edit the placed activator's properties as well: set pkChildObject to the placed mask itself.
Test it![edit | edit source]
Load the cell in-game. You'll most likely find your Dragon Priest Mask lying on the floor near the statue. This is normal; we can't usually disable the mask's physics quickly enough OnInit.
Walk up to the statue and activate it a few times to randomize its rotation. (The statue's origin lies on its bottom surface, so it may clip through the ground several times. You may need to use the tcl command to view it.) You should find that the mask is positioned properly on the statue's face with every random rotation.
Notes[edit | edit source]
Most applications of this library will follow the same basic format as the setup described above: you'll define the position and rotation of some "child" relative to the "parent," and then apply a script that feeds the child, parent, relative position, and relative rotation into my library.
Examples of parent-child relationships:
- Keeping a Door inside of a door frame that can be moved at run-time
- Keeping a Light anchored to a light source (e.g. wall sconce) that can be moved at run-time
- Repositioning the invisible DummyBookMarkers in a bookshelf, when moving the bookshelf at run-time
- I don't know if you can spawn and move trigger zones at run-time. If so, then with minimal work, it should be possible to incorporate bookshelves in home decoration mods!