• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

How to update unit height smoothly?

Status
Not open for further replies.
Level 5
Joined
Nov 27, 2007
Messages
85
I have a ball in my map and I need to make its vertical movement smooth.
Currently its height and vertical speed are updated every 0.1 sec.
0.1 sec isn't perfect and it looks rough to the naked eye, especially when vertical speed is high.
It would be logical to simply update the vertical position/speed in 0.01 or 0.05 periodic trigger, yes, but this would require major reconstruction of the map and a lot of testing.

So I was wondering, about other ways to achieve smoothness effect.
For example, what about using an action (a func?) that smoothly changes unit height within passed time-argument.

So my question is - Is there a way to smoothly update unit fly height, like so:
JASS:
function UnitUpdateHeightSmoothly takes unit u, real new_height, real time

I can rememberr third argument in SetUnitFlyHeight func:
JASS:
native SetUnitFlyHeight takes unit whichUnit, real newHeight, real rate returns nothing
Rate is definitely not "time" argument, but perhaps it can be used somehow to emulate time?


Here's how vertical speed/height are updated in my map:
JASS:
function UpdateBallVerticalPositionAndHeight takes nothing returns nothing
     real h_ball = GetUnitHeight(udg_Ball)
     call SetBallHeight(h_ball + udg_BallVZ) // udg_BallVZ is vertical speed per 0.1 second, so it can be used without a multiplier here
     set udg_BallVZ=udg_BallVZ - udg_G // subtract G from vertical speed
endfunction
 
Rate for the SetUnitFlyHeight() function is how long it will take for the unit to fly up to the height value you've placed. If you use "0" for rate and 400 for fly height, it will instantly acquire the height of 400. If you use "500" for rate and 400 for fly height, it will take 0.8 seconds to reach that height.

So, using the 'rate' parameter in this case is highly suggested.
 
Level 5
Joined
Mar 22, 2009
Messages
170
Rate is the rate of change of the height, as in, if it is 400, its 400 per second.
The correct value for that to make smooth motion, is
abs(current height - wanted height) * duration
 
Status
Not open for further replies.
Top