Author Topic: Setting the Translate Path for an object  (Read 933 times)

Offline sushobhit

  • long
  • ***
  • Posts: 109
  • future is now
    • View Profile
Setting the Translate Path for an object
« on: March 30, 2014, 02:39:24 pm »

Actually i was working on a Project regarding  a Prison.
In the prison there are 20 convicts . Out of 20 one is our hero & he has to escape the prison.
I have set up the Prison enviornment. It has JailCells , 2 Basketball Courts , Medicine Room , Cafe etc etc.

Now ,
The hero is controlled by the user using MotionTouch Events. So that's not a problem.
The problem is the rest of convicts operate by AI(Artificial Intelligence) so they have to be programmed.

Now ,
I want to set a Path for each konvict like :

Path Start (JailCell)     ->                               Path End (BasketBall Court)
So once the path is set set the object should translate itself from jailcell to the basketball court.

One thing is I simply translate(jail) -> translate(BBCourt) but that looks very robotic.

I want it to look humanly
To Egon : Like you have class ParticleManager , any class for PathMaker if YES please share

And also the object should avoid any collisions in between

What should I do , what is the most Optimised way of achieving this...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11899
    • View Profile
Re: Setting the Translate Path for an object
« Reply #1 on: March 30, 2014, 09:08:08 pm »
I'm doing something very similar in my RPG, but the code is to convoluted to be useful for anybody but me. What i'm basically doing is to take the current position of an entity, create the direction vector (a) to the target and rotate the entity in a way that it's direction vector (b) slowly turns towards that vector a. Then move the entity into the direction in which it's facing. That way, they move more natural around sharp edges in the path.

For reference, this is the part that does the interpolation:

Code: [Select]
                        dir.set(p.x, 0, p.z);
tmp.set(current.x, 0, current.z);



if (!reached && entity != null) {
if (ticks == 1) {
entity.getRotation().interpolate(entity.getRotation(), tmpMatrix, 0.51f);
} else {

Offline kkl

  • float
  • ****
  • Posts: 291
    • View Profile
Re: Setting the Translate Path for an object
« Reply #2 on: March 31, 2014, 03:36:09 am »
You might wanna look at Bezier Path or Catmul-Rom Path. They are very useful in translating your 3D object along the path. It's hard to build that math algorithm from scratch, but fortunately, some did it. This library has the algorithm available, you can check the source code.
« Last Edit: March 31, 2014, 04:33:06 am by kkl »