Jump to content

Script: A self rotating object


Zorkaz

Recommended Posts

I didn't find a vanilla script or a forum entry, so I'm posting this simple script here for people who want to expand it and look for such a script via google

 

  Quote

 

Scriptname HRLLighthouseLightRotation extends ObjectReference
int zaxis = 0




event oncellload()
While self.isenabled()

self.SetAngle(0.0, 0.0, zaxis)
zaxis = zaxis + 1
If Zaxis == 360
Zaxis = 0
EndIf

endwhile



endevent


 

I used it on a lighthouse light by the way

One might add utility.wait (<insert number here>) to make it go slower

Link to comment
Share on other sites

With the zaxis counter constantly incrementing, after a period of time it will overflow (probably at 2,147,483,647).


Whilst that is a long way away, publishing unbounded stuff is bad practice when it is simple to manage:




If Zaxis == 360
Zaxis = 0
EndIf

Link to comment
Share on other sites

You can also use TranslateTo, I think it can do a smoother movement, and you can adjust the speed with more accuracy.

Scriptname Rotate extends ObjectReference

Float Property fRotationSpeed = 200.0 Auto

Event OnCellLoad()
	SetMotionType(Motion_Keyframed);some objects need this to move their collision alongside the mesh.
	RotateOnce()
EndEvent

Function RotateOnce()
	TranslateTo(X, Y, Z, GetAngleX(), GetAngleY(), GetAngleZ() + 180, 100.0, fRotationSpeed)
EndFunction

Event OnTranslationAlmostComplete()
	RotateOnce()
EndEvent

Function SetSpeed(Float Speed)
	fRotationSpeed = Speed
EndFunction

I added a SetSpeed function so you change the rotation speed from the console, by clicking on the object that has the script attached and for example:

cf setspeed 25

Additionally, if you want it to rotate in one of the other angles you just need to set "+ 180" in the angle that you want to rotate the object:

 

Rotate vertically, left to right:

TranslateTo(X, Y, Z, GetAngleX(), GetAngleY() + 180, GetAngleZ(), 100.0, fRotationSpeed)

 

Rotate vertically, back to front.

TranslateTo(X, Y, Z, GetAngleX() + 180, GetAngleY(), GetAngleZ(), 100.0, fRotationSpeed)

 

The direction of the rotation is almost random, if you want to ensure the rotation direction use +/- 179, it will force the rotation to one side or the other.

Edited by DieFeM
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...