Define World Limits based on moving object?
by Deozaan · in Torque Game Builder · 04/07/2008 (8:39 am) · 4 replies
Is it possible to define an object's World Limits based on another object's position?
For instance, if I always wanted another object to be within 10 world units of a moving object, but wanted it to be able to freely move within those limits?
For instance, if I always wanted another object to be within 10 world units of a moving object, but wanted it to be able to freely move within those limits?
#2
Thanks a lot for the information! I read it some time ago but somehow forgot to say thanks! Sorry about that. :-)
05/21/2008 (6:58 pm)
James:Thanks a lot for the information! I read it some time ago but somehow forgot to say thanks! Sorry about that. :-)
#3
05/22/2008 (11:02 am)
Best of luck!
#4
06/21/2008 (12:42 pm)
Can we mount objects to the camera? cause then we could set up several objects off screen linked to the camera to act as moving world limits.
Associate James Ford
Sickhead Games
$wlOffset = "10 10"; $wlUpdateInterval = 300; function updateWorldLimits( %obj1, %obj2 ) { if ( !isObject( %obj1 ) || !isObject( %obj2 ) ) return; %pos = %obj2.getPosition(); %min = t2dVectorSub( %pos, $wlOffset ); %max = t2dVectorAdd( %pos, $wlOffset ); %obj1.setWorldLimits( %obj1.worldLimitMode, %min SPC %max, %obj1.worldLimitCallback ); schedule( $wlUpdateInterval, %obj1, updateWorldLimits, %obj1, %obj2 ); }Setting the mode to clamp would accomplish what you want I believe. It could have some issues though...
Since this update is happening in script through a schedule... it can, at most, happen once per tick. For that, and other reasons, it could result in a popping look when the limits are updated and the object is "teleported" back inside the world limits. On the other hand, without testing this, it could actually not work at all, but its a starting point.
You might want to investigate using impulses to keep the object inside the "bounds". For instance, if you store the object's "desired" velocity ( calculated by play input or some AI ), then add to it some "steering" velocity to keep it within the bounds, you might get a smoother look ( but it wouldn't be guaranteed to stay in the bounds ). This too would need to be calculated each tick or relatively frequently.