holschuh Posted June 19, 2015 Share Posted June 19, 2015 Hi, is there an simple Statement to move an entity from one vec3 to an other in steps ... means smoth not in one big jump. I think this is somethin in math but i am not good in Vector math... Have you an snippet for me or an kick into the right direction <-wordplay cu Volker Quote Link to comment Share on other sites More sharing options...
CreativeOcclusion Posted June 19, 2015 Share Posted June 19, 2015 If you are using a navmesh you can use GoToPoint... http://www.leadwerks.com/werkspace/page/api-reference/_/entity/entitygotopoint-r700 Quote Link to comment Share on other sites More sharing options...
holschuh Posted June 19, 2015 Author Share Posted June 19, 2015 this is an idea but i need it for a realy simple movement along x and z axis on same y Level with no barrier in the way. Quote Link to comment Share on other sites More sharing options...
Naughty Alien Posted June 19, 2015 Share Posted June 19, 2015 ..here is smoothing function you can use..it will calculate one variable of your choice, which can be either angle or position, etc.. float New_Value(float destination, float current, float numberOfSteps) { if(abs(destination-current)<0.01) { return destination; } else { return(current+((destination-current)/numberOfSteps)); } } ..so, in your main loop, you will just feed function with required data: -destination That is where you want your object to go. It can be X, Y or Z coordinate. For each coordinate use function with appropriate values. -current This value representing current value of your object position. I dont know how you capturing that with LE3, but this is value of current position your object is at. -numberOfSteps This value is number of steps your motion will take before reach its destination. So, if you wanna move your object to new position, for example X=10, Y=100, Z=-14, in 30 steps then your loop should look like this.. //Loop Start Here float current_X=GetXPositionWithLE3Command(MyObject); float current_Y=GetYPositionWithLE3Command(MyObject); float current_Z=GetZPositionWithLE3Command(MyObject); float new_X=New_Value(10.0, current_X, 30.0); float new_Y=New_Value(100.0, current_Y, 30.0); float new_Z=New_Value(-14.0, current_Z, 30.0); PositionEntityCommandInLE3(MyObject, new_X, new_Y, new_Z); ...... //Loop End Here ... ..this will give you nice, smooth motion (or rotation, depend what you want to update)..I hope this helps.. Quote Link to comment Share on other sites More sharing options...
Josh Posted June 19, 2015 Share Posted June 19, 2015 I believe this will do it (may have typos): function MoveToPoint(entity,target,speed) local currentpos = entity:GetPosition(true) local diff = target - currentpos if diff:Length() < speed then entity:SetPosition(target) else diff = diff:Normalize() * speed entity:Translate(diff.x,diff.y,diff.z,true) end end Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Rick Posted June 19, 2015 Share Posted June 19, 2015 https://github.com/kikito/tween.lua This is a lua tween library (I didn't make it). Honestly something like that built-in would be ideal. Would be nice to just be able to say move from here to here over x seconds using this kind of easing. Quote Link to comment Share on other sites More sharing options...
shadmar Posted June 19, 2015 Share Posted June 19, 2015 LE already have have a simple interpolation function: http://www.leadwerks.com/werkspace/page/api-reference/_/math/mathcurve-r602 Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
holschuh Posted June 19, 2015 Author Share Posted June 19, 2015 Hi, Naughty Aliens code is the way i did it by myself but i hoped the engine save some work for me... Josh's snippet did it for me was easy to include into my other stuff. i have to learn some matrix and Vector math like the normalize length and translate ... this can save many lines i break down at the moment to single integer math with many helper variables ... thanks all for help cu Volker Quote Link to comment Share on other sites More sharing options...
Naughty Alien Posted June 20, 2015 Share Posted June 20, 2015 ..well..just put mentioned code in to some nice function you can call in one line any time you want and you are good to go.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.