Jump to content

is there an simple statement to move an entity from one vec3 to another - in steps?


holschuh
 Share

Recommended Posts

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

Link to comment
Share on other sites

..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..

 

Link to comment
Share on other sites

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

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

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

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...