ajs52698 Posted December 10, 2019 Share Posted December 10, 2019 (edited) The available functions that can be used to rotate Object references only do so using global rotations. How can one rotate an object's local rotation along say its X axis, using global rotations? I've attached a rough representation of what i'd like to accomplish. And yes, i have searched for information on this and have found something : https://www.creationkit.com/index.php?title=Setting_Local_Rotation, but have had no success with this. If i'm mistaken, any help is appreciated! Edited December 11, 2019 by ajs52698 Link to comment Share on other sites More sharing options...
ReDragon2013 Posted December 10, 2019 Share Posted December 10, 2019 (edited) If you not have seen already https://www.creationkit.com/index.php?title=SetAngle_-_ObjectReference two vanilla sample scripts as follow, only copy and paste SovngardeStatueScript Scriptname SovngardeStatueScript extends ObjectReference {script to make statues creepily turn to look at you when you're not watching} import math float fStartingAngle float property fMaxDelta = 65.0 auto ; max total change from starting angle (+/-) float property fMaxChange = 20.0 auto ; max change per update float property fMinChange = 1.0 auto ; don't turn if change less than this float fZTranslation = 1.0 float fAngleAdjustment = 180.0 ; account for the fact that the statue is facing backwards (art) bool property bDebug = false auto Event OnInit() fStartingAngle = GetAngleZ() endEvent event OnCellLoad() if MQ305.GetStage() < 10 || MQ305.GetStage() >= 200 self.setMotionType(Motion_Keyframed, TRUE) RegisterForUpdate( Utility.RandomFloat(4.0, 7.0) ) else UnregisterForUpdate() endif endEvent event OnUnload() UnregisterForUpdate() endEvent event OnCellDetach() UnregisterForUpdate() endEvent Event OnUpdate() ; check if player has LOS if !Is3DLoaded() ; failsafe UnregisterForUpdate() elseif Game.GetPlayer().HasLOS( self ) == 0 ; if so, rotate towards player if not looking at him, and not already rotated to max angle float fHeadingAngle = GetHeadingAngle( Game.GetPlayer() ) ; ; debug.TraceConditional(self + " fHeadingAngle = " + fHeadingAngle, bDebug) fHeadingAngle = fHeadingAngle + fAngleAdjustment ; add 180 because of opposite rotation of statue art? ; ; debug.TraceConditional(self + " ADJUSTED fHeadingAngle = " + fHeadingAngle, bDebug) ; would we turn outside our maxDelta? float fNewAngle = fHeadingAngle + GetAngleZ() ; ; debug.TraceConditional(self + " fNewAngle = " + fNewAngle, bDebug) if fNewAngle < 0 fNewAngle = fNewAngle + 360 ; ; debug.TraceConditional(self + " fNewAngle = " + fNewAngle, bDebug) endif float fDelta =fNewAngle - GetAngleZ() ; ; debug.TraceConditional(self + " fDelta = " + fDelta, bDebug) ; if rotating past 180, use negative if fDelta > 180 fDelta = fDelta - 360 elseif fDelta < -180 fDelta = fDelta + 360 endif if fDelta > 0 ; ; debug.TraceConditional(self + " Turn to the right: NEW fDelta = " + fDelta, bDebug) else ; ; debug.TraceConditional(self + " Turn to the left: NEW fDelta = " + fDelta, bDebug) endif ; can we change this much? if Abs(fDelta) > fMaxChange if fDelta < 0 fDelta = fMaxChange * -1.0 else fDelta = fMaxChange endif endif ; ; debug.TraceConditional(self + " UPDATED fDelta = " + fDelta, bDebug) ; use updated fDelta to calculate real new angle fNewAngle = GetAngleZ() + fDelta ; ; debug.TraceConditional(self + " UPDATED fNewAngle = " + fNewAngle, bDebug ) if Abs(fNewAngle - fStartingAngle) <= (fMaxDelta) && abs(fDelta) > fMinChange unregisterForupdate() ; ; debug.TraceConditional(self + " TURNING...", bDebug) ; go ahead and turn translateTo(self.x,self.y,self.z + fZTranslation,self.getAngleX(),self.getAngleY(),fNewAngle,100,0) ;setAngle(GetAngleX(), GetAngleY(), fNewAngle) endif endif endEvent Event OnTranslationComplete() ; ; debug.traceConditional(self + "OnTranslationComplete", bDebug) fZTranslation = fZTranslation * -1.0 RegisterForUpdate( Utility.RandomFloat(4.0, 7.0) ) endEvent Quest Property MQ305 Auto MiddenEnchantedSkull scriptName MiddenEnchantedSkull extends objectReference {just a fun visual toy} import utility float property maxRotate auto float property maxMove auto effectShader property IllusionFearFXS auto bool Up float bob ; amplitude EVENT onLoad() if maxRotate == 0 maxRotate = 359.0 endif IllusionFearFXS.play(self) if is3Dloaded() == TRUE registerForSingleUpdate(1.0) endif endEVENT EVENT onUpdate() ; ;debug.trace("JOEL DEBUG: Enchanted Skull Updating") ; ;debug.trace(self) if UP == TRUE bob = maxmove UP = FALSE else bob = -1*maxmove UP = TRUE endif translateTo(self.x, self.y, (self.z+bob), 0, 0,randomFloat(1,maxRotate), 0.15) if is3Dloaded() == TRUE registerForSingleUpdate(3.0) endif endEVENT Edited December 10, 2019 by ReDragon2013 Link to comment Share on other sites More sharing options...
maxarturo Posted December 10, 2019 Share Posted December 10, 2019 (edited) I had a similar problem with one custom activator that i needed to have such rotations, but i encounter a few problems with the script creation, so i ended up replacing an animated vanilla mesh with my custom mesh and using PlayAnimation() + TranslateTo() the edited vanilla object to have the result i needed. Although, i did manage to achieve a relative close to the desire first approach (using just one script), by using the logic of the following script (example), but i didn't finish it cause i had a much more satisfying result with my second approach (smaller script + more flexible). https://www.creationkit.com/index.php?title=Spatial_functions_and_snippets https://www.creationkit.com/index.php?title=SetAngle_-_ObjectReference I hope it helps... Edit: Typo... + Apparently we post the same thing (more or less) at the same time.... Edited December 11, 2019 by maxarturo Link to comment Share on other sites More sharing options...
Cheyron Posted December 11, 2019 Share Posted December 11, 2019 based on that image you just want to rotate around the z axis... just add or subtract to the z angle... this type of code would work... you dont need any trig functions to rotate around the z axis (change heading) Float Function GetNewZAngle(ObjectReference o, Float rotate) Float z = o.GetAngleZ() z += rotate If z >= 360 z -= 360 ElseIf z < 0 z += 360 EndIf Return z EndFunction you could do that for any angle... you only really need the trig if you needed to actually move the object's position... some game engines will even correct the heading if you give it a negative value or value >= 360 Link to comment Share on other sites More sharing options...
ajs52698 Posted December 11, 2019 Author Share Posted December 11, 2019 I realize now the picture is a little misleading to what I wanted help with, ill redo it. Sorry for confusion. Link to comment Share on other sites More sharing options...
ajs52698 Posted December 19, 2019 Author Share Posted December 19, 2019 (edited) You I had a similar problem with one custom activator that i needed to have such rotations, but i encounter a few problems with the script creation, so i ended up replacing an animated vanilla mesh with my custom mesh and using PlayAnimation() + TranslateTo() the edited vanilla object to have the result i needed. Although, i did manage to achieve a relative close to the desire first approach (using just one script), by using the logic of the following script (example), but i didn't finish it cause i had a much more satisfying result with my second approach (smaller script + more flexible).https://www.creationkit.com/index.php?title=Spatial_functions_and_snippets https://www.creationkit.com/index.php?title=SetAngle_-_ObjectReference I hope it helps... Edit: Typo... + Apparently we post the same thing (more or less) at the same time.... Your second link is to the set angle wiki page, is this intended? I assumed after reading your post that you were trying to link your script as an example. Edited December 19, 2019 by ajs52698 Link to comment Share on other sites More sharing options...
maxarturo Posted December 19, 2019 Share Posted December 19, 2019 I wasn't trying to post a script, they are just links containing the relevant info. * It would be much more easier for the reader that's trying to assist you, if you explain in detail what you are trying to do. Link to comment Share on other sites More sharing options...
Recommended Posts