Game Development Community

How to a t2dSceneObject follows a vector2d position array

by Michele Condo' · in iTorque 2D · 03/09/2011 (10:55 am) · 7 replies

Hi to all!
First of all, I'm sorry in advance for my bad English :P

Second.. I love iTorque2D!! ^^


Now.. the question...

I've an array of world position point, I want a t2dSceneObject follows the "imaginary" curve that the point array describe.

I've try with %obj.moveTo(x,y,...) for every point (making a "for" statement for every points), but if this point array decribe a curve, the t2dSceneObject go from first point to the last point, excluding the intermediate location points.
I want that t2dSceneObject make follow the path described in array point, passing to every intermediate points.

Can you help me pls?

Thanks!

#1
03/09/2011 (11:46 am)
I wanted flying objects that followed curves so what I did was I made an array that would be populated by the mouse position every 100 MS then I moved the mouse around the screen in the way I wanted the object to fly.

I saved my path to a file then at runtime I open the file, get the array and schedule a moveTo on my object every 100MS to get it to follow the path I made.

Might not work for what you want but it worked great for my application of having an object follow a static, curved path.

#2
03/09/2011 (2:11 pm)
Hi Chris!
Thanks for your reply. I tried same your solution. But as you said, it's not work well completely for me. For sure the object moving better than before, but even now not move in the right way. Now the object follows some intermediate points, but not all.
However I need to increase or decrease velocity of object that follows this array points, and schedule tecnique also slow the object velocity.

Maybe I need to make a lerp or slerp from a "keyframe" points of array, but I dont' know how to do this in torquescript. But I'm not sure that lerp or slerp can help me :D

I need help, sigh! And thanks again for your reply ^^
#3
03/09/2011 (2:21 pm)
I could be totally confusing this but are you saying that moveTo doesn't act on some of the points you feed it?

Have you considered using the onPositionTarget() callback?

Full definition of moveTo:

moveTo(t2dVector positionTarget, float linearSpeed,[bool autoStop=true],[bool callback=false],[bool snap=true],[float targetMargin=0.1])
#4
03/09/2011 (3:50 pm)
Hi!
I've used the moveTo, but for example if the points make a concave curve, if I use a simply "for" statement, the object go from first to last point directly, maybe because "for" statement is too fast.

Instead using the schedule, this work better but not fully, I need to be accelerate and decelerate the object and with schedule time I've also this issue.

I've make last try now, making a runtime t2dPath, and add every points as node of the t2dPath. Using runtime path the object follows the points in right way ^^

Now, I've only a problem... The facing object -.-' I've try to search online some code for facing, but I've a trouble to do this :D

Maybe can help me about this ^^'

Thanks again!
#5
03/09/2011 (4:27 pm)
For paths there's a function setOrient(%object, %orient) so that an object is always oriented constant to the direction of the path.

In general to have an object face another object you can do something like this:

%obj.setRotation( t2dAngleToPoint( %Position1, %Position2 ) );
#6
03/10/2011 (5:31 am)
Hello!
Thanks for answers!
I tried to use %path.setOrient(%obj, true) and for every callback when reached a new node the %obj.setRotation( t2dAngleToPoint( %currentPositionObject, %nextNodePosition ) ) method.

The rotation work perfectly, but I've a serious facing issue.
The object is a rectangle shape, for example 100px x 50px. I want this shape follows path created only from a side and rotate around a specified point and not rotating around center of shape.
To be more precise, if the shape is a rectangle, and the vertices are describes as A, B, C and D, I would the "face front" object is AB segment and follows path by this side and rotating around the point in middle of AB segment.

Maybe is hard, but I really need help..

Thanks in advance.. again.

Cya!
#7
03/10/2011 (10:43 am)
I'm struggling to picture this but perhaps using the mount offset is what you need?

mountt2dSceneObject::mount(t2dSceneObject object,[float offsetX=0],[float offsetY=0],[float mountForce=0],[bool trackRotation?=true],[bool sendToMount?=true],[bool ownedByMount?=true],[bool inheritAttributes?=true])