makzombie Posted October 12, 2015 Posted October 12, 2015 I'm trying to make an object move smoothly to the center of the player characters crosshair on Update every 0.01 seconds. Problem is the movment isn't smooth, the script engine might be a bit too slow to constantly update the position the object should move too. Does anyone have any ideas for a work around or better method of scripting this, or if this is something that is just not possible with the tools available? Here is the script I've created so far, attached to the player character through a spell effect using a furniture model as the object to translate. ScriptName ObjectTranslateTest extends activemagiceffect import Game import Math furniture property ObjectToSpawn auto objectReference ObjectRefToTranslate = none armor property armorIronHelmet auto actor property PlayerRef auto Event OnLoad() RegisterforSingleUpdate(0.01) EndEvent Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer) if akBaseItem == ArmorIronHelmet ObjectRefToTranslate = PlayerRef.Placeatme(ObjectToSpawn) akItemReference.disable() akItemReference.deleteWhenAble() PlayerRef.RegisterforUpdate(0.01) endif endevent Event OnUpdate() debug.notification("On Update.") float PlayerCharLookatXPos = PlayerRef.GetPositionX() + 120 * Sin(PlayerRef.GetAngleZ()) float PlayerCharLookatYPos = PlayerRef.GetPositionY() + 120 * Cos(PlayerRef.GetAngleZ()) float PlayerCharLookatZPos = PlayerRef.GetPositionZ() +PlayerRef.GetHeight() + -120 * Sin(PlayerRef.GetAngleX()) float afAngleX = 0 float afAngleY = 0 float afAngleZ = PlayerRef.GetAngleZ() float afSpeed = 100000 float afMaxRotationSpeed = 0.0 ObjectRefToTranslate.TranslateTo(PlayerCharLookatXPos,PlayerCharLookatYPos,PlayerCharLookatZPos,afAngleX,afAngleY,afAngleZ,afSpeed,afMaxRotationSpeed) RegisterforSingleUpdate(0.01) EndEvent
darkconsole Posted October 12, 2015 Posted October 12, 2015 ObjectRefToTranslate.StopTranslation() before the next TranslateTo() see if that helps. if its still not smooth that speed may be too high. speed should probably be more like 100 to get a smooth translatoin.
makzombie Posted October 12, 2015 Author Posted October 12, 2015 Looks a little smoother, though a problem with having the speed any lower is the object can't keep up with the player when I move around, and if I leave it at a high speed the movement still looks jittery. Could try to have the movement speed = a multiple of the distance between where the object should be and where it is so it speeds up when far away and slows down for smaller movements.
darkconsole Posted October 12, 2015 Posted October 12, 2015 Could try to have the movement speed = a multiple of the distance between where the object should be and where it is so it speeds up when far away and slows down for smaller movements. sounds like a decent solution.
makzombie Posted October 12, 2015 Author Posted October 12, 2015 Here's the updated script, still not that happy with the object moving through the player as runs forward, but the smaller movements look better. ScriptName ObjectMoveTest extends activemagiceffect import Math furniture property ObjectToSpawn auto objectReference ObjectRefToTranslate = none objectReference ObjectRefToMove = none armor property armorIronHelmet auto actor property PlayerRef auto Event OnLoad() RegisterforSingleUpdate(0.01) EndEvent Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer) if akBaseItem == ArmorIronHelmet ObjectRefToTranslate = PlayerRef.Placeatme(ObjectToSpawn) ObjectRefToMove = PlayerRef.Placeatme(ObjectToSpawn) akItemReference.disable() akItemReference.deleteWhenAble() PlayerRef.RegisterforUpdate(0.01) endif endevent Event OnUpdate() ObjectRefToMove.MoveTo(PlayerRef, 120.0 * Math.Sin(PlayerRef.GetAngleZ()), 120.0 * Math.Cos(PlayerRef.GetAngleZ()) ,PlayerRef.GetHeight() + -120 * Sin(PlayerRef.GetAngleX()),0) float PlayerCharLookatXPos = PlayerRef.GetPositionX() + 120 * Sin(PlayerRef.GetAngleZ()) float PlayerCharLookatYPos = PlayerRef.GetPositionY() + 120 * Cos(PlayerRef.GetAngleZ()) float PlayerCharLookatZPos = PlayerRef.GetPositionZ() +PlayerRef.GetHeight() + -120 * Sin(PlayerRef.GetAngleX()) float afAngleX = 0 float afAngleY = 0 float afAngleZ = PlayerRef.GetAngleZ() float afSpeed = ObjectRefToTranslate.GetDistance(ObjectRefToMove)*5 float afMaxRotationSpeed = 0.0 ObjectRefToTranslate.StopTranslation() ObjectRefToTranslate.TranslateTo(PlayerCharLookatXPos,PlayerCharLookatYPos,PlayerCharLookatZPos,afAngleX,afAngleY,afAngleZ,afSpeed,afMaxRotationSpeed) RegisterforSingleUpdate(0.01) EndEvent
darkconsole Posted October 12, 2015 Posted October 12, 2015 with a little bit of trig you could make it so that instead of where the crosshair is, its offset to the side. that way it will be by your side while you run around. i don't have time to work that out smoothly though while at work. basically you'd need the player angle, invent some triangles, and TranslateTo an offset location. from far away it would still look like it was more or less exactly on the crosshair, but up close it would just be like a meter off so it stands by your side. whatever it is this is.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.