Game Development Community

Bezier path. How to get a steady speed with an attached object?

by Dmitriy Stukalov · in Torque Game Builder · 07/04/2007 (1:57 am) · 13 replies

Hi,

If I attach some object to linear path then the object will move steady.
If I attach an object to a Bezier path then the object speed will change during their moving.

Is it correct beheavor?

What the reason of this speed changes?

#1
07/04/2007 (11:06 pm)
This is correct behaviour, you're right.
Speed is changes, because the difference in length between a path nodes.
The speed is constant from node to node though.

Update: "Speed is changes" is misprint here. It should be "time" here. In next sentence I said about speed. Thanks David.
#2
07/05/2007 (3:43 am)
Thank you Igor.

To this day I supposed that TGB developers have introduse a path feature as a way to store an object trajectory only (not speed). If this is not the case, may be someone now some mathematical equations to describe object moving?
#3
07/05/2007 (6:42 pm)
@Igor, actually, I'm gonna have to disagree with you there ...

The speed of the object should be constant, regardless of the arc of the path -- if you say "move forward at 50 units per second" ... it should move forward at 50 units per second, and if the arc increases the distance from A to B ... then it takes longer to get to B from A at 50 units ...

@Dmitriy, this does sound like a goof ... what version of the engine are you using and can you provide the code your using to make the objects move ... is there any extra code that runs behind the scenes (schedules or onUpdateScene code)?

I'm going to test this out in a bit and I'll post back here my findings ...


#4
07/05/2007 (7:09 pm)
Ok -- just tested this ... and it works the way I thought it would/should.

I created a 4-node path with each node of the path spaced 4 grid sections apart from each other, effectively creating a perfectly square path ... I then changed the path mode to bezier and pulled and twisted the path so it was really whacky looking ...

I mounted an object to the path (the spaceship provided with TGB) and told it to track rotation and move at a speed of 10 ...

The object moved along the path at a steady constant speed and did not arrive at each node within a set period of time ... the distance to the next node was always different from the last node-to-node distance and the object took it times when applicable to get to the next node ...

The only thing I did notice was when the object got back to the first node, it appeared to 'leap forward' over the node ... using the 'wrap' for my follow mode ... this gave the object the appearance that it was moving faster ... but I don't know whether it's really a bug, or just the mode I used ...

Dmitry, any chance you can provide some detail about your problem specifically?

#5
07/05/2007 (10:18 pm)
Thank you for your time, David,

But I still have problems with a path object. Could you test my path? Please insert folloving path datablock to your *.t2d level file.

new t2dPath() {
      pathType = "BEZIER";
      canSaveDynamicFields = "1";
      position = "-11.469 -7.598";
      size = "102.401 29.860";
         mountID = "3";
         node0 = "39.731468 -22.528152 -45.000000 17.589092";
         node1 = "33.406906 7.332014 -118.919891 8.911849";
         node2 = "-62.669220 -6.144041 -180.000000 56.357132";
         nodeCount = "3";
         object0 = "4 0 -1 30.000000 1 1 0.000000 -1 RESTART";
         objectCount = "1";
   };

The path have three node and looks like an egg. Place some object to node 0 (right top node) and set object speed to 30. Then run the level.
Please notice, when an object move under node 1, then its speed slow down!

I use Torque Game Builder version 1.1.3.
#6
07/05/2007 (10:36 pm)
Dmitry,

I see what your talking about ... and here's what I noticed ... when the object starts to move (from left to right) it 'jerks' (or 'leaps') through node0 ... and when it gets to node1 ... it 'jitters' along the path ... watch very carefully at a zoomed in level ... turn on all the debug rendering too ... it's almost as if the engines choking on the 'smoothness' of the curve ...

I definately think this is qualifies as a 'goof' ... dunno bout a bug, but looks like a bonified 'oops' to me ;)


I added two more nodes to your path, and tried to reproduce the 'egg' smoothness ... with my wonderful skills I failed to make it 'perfect' but it was pretty darn close ... and the problem still persisted ...

I ran some more tests, added a new node to your path and changed the angle of the bezier ... still a bit goofed;

new t2dPath() {
      pathType = "BEZIER";
      canSaveDynamicFields = "1";
      position = "-8.704 9.379";
      size = "62.593 68.758";
         mountID = "2";
         node0 = "0.000000 -25.000000 -76.845116 35.663544";
         node1 = "22.592520 5.000000 -135.000000 26.882170";
         node2 = "2.853795 43.758137 90.000000 64.423111";
         node3 = "-40.000000 -5.000000 -315.000031 48.662434";
         nodeCount = "4";
         object0 = "3 3 2 10.000000 1 1 0.000000 -1 WRAP";
         objectCount = "1";
   };

that's the path I wound up with ... and I'm noticing that whenever the object reaches a section that has a lot of pixels (with debug render on) ... it seems to slow down ... almost as if the engine is choking on where to go next with the object ...

So ... short of having a really brilliant answer for you, I would suggest that you try to keep your bezier's simple ... seems the less complex the curve is, the smoother the movement is ...

I would also suggest trying this in TGB 1.5 ... not sure if they tweaked any of the path code, but it's possible someone noticed this at some point and applied a quick fix to it thats sitting in the 1.5 tree ...
#7
07/06/2007 (12:01 am)
David,

Thank's a lot for you valuable notes.

Within the next few days I will try my path in TGB 1.5. (May be someone have any chance to try it right now?)

As regards your brilliant suggestion... I need really complex curves. Only one way I see - to cut my complex path to a great many short sub-pathes. OK. I will try it as well, but I supposed that CATMULL splines more appropriable to this case.
#8
07/09/2007 (1:15 am)
OK, I have tested my paths in 1.5.
Unfortunately, this version of TGB still have problems with object pathing.

During my work I have found several rules to make object movement more smooth.
1. Place path nodes regulary.
2. Keep nodes power equal for all nodes.
3. Avoid sharp bends.

These rules (restrictions) bring down usability of Bezier paths.

Furthermore, path editor in TGB is inconvenient for complicated paths. Probably I will make more convenient path editor for TGB.
#9
07/10/2007 (4:54 am)
Hello,

I've created simple but more convenient path editor.

Main features:
- creating Bezier paths,
- loading background images,
- saving your work (string raw data),
- exporting created path as datablock and as image,
- several nice features.

Screenshot.
Download link

May be it will useful!
Any comments, suggestions will be appreciated.
#10
07/10/2007 (1:23 pm)
Nice tool - especially for complex paths. Found the selective display options handy as well.
#11
07/10/2007 (10:02 pm)
Thank you Kally,

Now version 0.5.1 available for download (same links).

Option added:
+ Saving a path as nodes sequence.

Bug fixed:
- Inserting a node for node count less then 2.
- Incorrect inserting a node for 50% scale.
#12
07/17/2007 (12:48 pm)
Pretty good tool indeed... gonna give it a try ... keep up the good work m8.
#13
07/18/2007 (11:42 pm)
Version 0.5.2 is available at the same location.

Option added:
+ The default background with rullers.
+ Cleaning of the background.