Xilandro Posted November 2, 2013 Share Posted November 2, 2013 (edited) I'm trying to make smooth transition between two position coordinates, and as far as i see - there's no easy ways to make it. It's not superimportant for my mod, but it will make it much better. I'm perfectionist, and i can't just leave it as it is.I want to move Player from one X + Y coord to other X + Y coord, but smoothly, without teleportation.Basic script looks like this: set Angle to ObjectRef.GetAngle Z set sine to (sin Angle) set cosi to (cos Angle) set Dist to -50 set CoordX to ObjectRef.GetPos X + (Dist * sine) set CoordY to ObjectRef.GetPos Y + (Dist * cosi) Player.SetAngle Z Angle Player.SetPos X CoordX Player.SetPos Y CoordYMaybe it can be made with timer, something like this? if timer == 0.1 set coordX to (CoordX + 1) Player.SetPos X CoordX elseif timer == 0.2 set coordX to (CoordX + 1) Player.SetPos X CoordX elseif timer == 0.3 set coordX to (CoordX + 1) Player.SetPos X CoordX Edited November 2, 2013 by Xilandro Link to comment Share on other sites More sharing options...
jazzisparis Posted November 2, 2013 Share Posted November 2, 2013 This is how I'd do it: float fSpeed float fPlayerX float fPlayerY float fDiffX float fDiffY float fDist float fStepX float fStepY float fAux short bInit short iFrames begin GameMode if bInit set bInit to 0 set fSpeed to 100 set fPlayerX to player.GetPos X set fPlayerY to player.GetPos Y set fDiffX to ObjectRef.GetPos X - fPlayerX set fDiffY to ObjectRef.GetPos Y - fPlayerY set fAux to (Pow fDiffX 2) + (Pow fDiffY 2) set fDist to Pow fAux 0.5 set iFrames to (fDist / fSpeed) * 60 set fStepX to fDiffX / iFrames set fStepY to fDiffY / iFrames endif if iFrames set iFrames to iFrames - 1 set fPlayerX to fPlayerX + fStepX set fPlayerY to fPlayerY + fStepY player.SetPos X fPlayerX player.SetPos Y fPlayerY endif end You initialize the sequence by setting bInit to 1, after you have positioned ObjectRef. Set fSpeed to the distance (in game units) you want the player to move in one second. In this example, it is 100 gu/sec. Obviously, you will have to test it in-game and tweak it. Note that if this is to be a part of a quest script, you need to set the Script Processing Delay to 0.016. Link to comment Share on other sites More sharing options...
Xilandro Posted November 2, 2013 Author Share Posted November 2, 2013 jazzisparisOh wow. It's amazing. Thank you! I will try it asap) Link to comment Share on other sites More sharing options...
Xilandro Posted November 2, 2013 Author Share Posted November 2, 2013 (edited) jazzisparis Works like a charm. Added angle X and Z calculation as well.And script is pretty huge =) Thanks again. Here's the result.updSeems like angle transition breaks the script if difference between angles is small =( int Dist float X float Y float TempX float TempY float ang float sine float cosi ref ObjectRef float DiffX float DiffY float DistU float StepX float StepY float Aux int Frames float DiffAngZ float DiffAngX float DistAng float StepAngZ float StepAngX float AuxAng int FramesAng float Speed int bInit Begin GameMode if Action set bInit to 1 XMarkerRef.MoveTo ObjectRef set ang to ObjectRef.GetAngle Z set sine to (sin ang) set cosi to (cos ang) set DistU to -30 set X to ObjectRef.GetPos X + (DistU * sine) set Y to ObjectRef.GetPos Y + (DistU * cosi) XMarkerRef.SetPos X X XMarkerRef.SetPos Y Y XMarkerRef.SetAngle Z Ang XMarkerRef.SetAngle X 10 endif if bInit set bInit to 0 set Speed to 100 set TempX to player.GetPos X set TempY to player.GetPos Y set AngZ to player.GetAngle Z set AngX to player.GetAngle X set DiffX to XMarkerRef.GetPos X - TempX set DiffY to XMarkerRef.GetPos Y - TempY set DiffAngZ to XMarkerRef.GetAngle Z - AngZ set DiffAngX to XMarkerRef.GetAngle X - AngX set Aux to (Pow DiffX 2) + (Pow DiffY 2) set AuxAng to (Pow DiffAngZ 2) + (Pow DiffAngX 2) set Dist to Pow Aux 0.5 set DistAng to Pow AuxAng 0.5 set Frames to (Dist / Speed) * 60 set FramesAng to (DistAng / Speed) * 60 set StepX to DiffX / Frames set StepY to DiffY / Frames set StepAngZ to DiffAngZ / FramesAng set StepAngX to DiffAngX / FramesAng endif if Frames set Frames to Frames - 1 set TempX to TempX + StepX set TempY to TempY + StepY player.SetPos X TempX player.SetPos Y TempY endif if FramesAng set FramesAng to FramesAng - 1 set AngZ to AngZ + StepAngZ set AngX to AngX + StepAngX player.SetAngle Z AngZ player.SetAngle X AngX endif End Edited November 2, 2013 by Xilandro Link to comment Share on other sites More sharing options...
jazzisparis Posted November 2, 2013 Share Posted November 2, 2013 Doing the same thing with angles is a bit more tricky, especially with the Z angle, which ranges 0 to 180, then -179.9999 to -0.0001 (clockwise), not 0 to 359.9999. Can you elaborate a little what you're trying to accomplish? Link to comment Share on other sites More sharing options...
Xilandro Posted November 2, 2013 Author Share Posted November 2, 2013 which ranges 0 to 180, then -179.9999 to -0.0001 (clockwise), not 0 to 359.9999.didn't know. Dat engine... Can you elaborate a little what you're trying to accomplish? Yes. I will send you PM. Link to comment Share on other sites More sharing options...
Recommended Posts