Smooth Non-Linear Movement Without Mounting, How?
by Leo Gura · in Torque Game Builder · 11/26/2006 (5:14 pm) · 4 replies
The goal is fairly simple, to create objects in 2D that move smoothly yet in a non-linear fashion within a certain region of the screen (imagine a moving molecule simulation). One technique I've used is to create the object in question, mount it to another invisible object, set the mount force to something other than 1, and then have the invisible object moveTo() randomly selected coordinates within a predefined region. However, with possibly hundreds of objects in the scene at any given time, I'm beginning to experience low framerates, and as such, have decided to look for a more efficient code; one not requiring the use of invisible objects.
How else might this sort of movement be accomplished? Currently I'm playing around with using constant forces but am finding that I lack control over my objects. Figuring out the necessary amount of force to apply, and when, is proving to be a major challenge. A perfect example of what I'm trying to accomplish is the enemy movement found in Geometry Wars. The movement isn't strictly linear, it's fairly random, it's confined to a certain space, it's smooth, and it closes onto the player. Is there a way to construct such movement without mounting, keeping in mind of course that any such alternative should be at least as efficient as mounting, but hopefully moreso.
Thanks.
How else might this sort of movement be accomplished? Currently I'm playing around with using constant forces but am finding that I lack control over my objects. Figuring out the necessary amount of force to apply, and when, is proving to be a major challenge. A perfect example of what I'm trying to accomplish is the enemy movement found in Geometry Wars. The movement isn't strictly linear, it's fairly random, it's confined to a certain space, it's smooth, and it closes onto the player. Is there a way to construct such movement without mounting, keeping in mind of course that any such alternative should be at least as efficient as mounting, but hopefully moreso.
Thanks.
#2
11/28/2006 (1:06 pm)
The AI part I can handle myself, what I'm talking about is having a set of x,y coordinates to which an object needs to move and having it get there without mounting. I guess the ultimate question is this: How can I use forces to guide an object to a point supposing that object already has some velocity?
#3
12/04/2006 (3:49 am)
If you want to use forces, just apply a force in the direction of the target position. Maybe I'm not understanding the question.. ?
#4
I wanted to have a race car accelerate, myself. I ended up managing most of the properties myself instead of using forces in TGB. My simulation was pretty hacky, but it ended up looking excellent (I think). =)
I made a dynamic variable for acceleration (so that I could tweak it around in the editor).
%this.getLinearVelocity() holds our current velocity
A vector variable can be instantiated with:
%myVect = "1.0 0.0 0.0";
To get fields of the vector, use getWord(, ), so to set a new velocity:
%this.setLinearVelocity(getWord(myVect, 0), getWord(myVect,1) );
To keep track of time you can use getSimTime(), or you can just schedule updates at regular time intervals
using the schedule function. For example:
%this.schedule(%this.updateTime, "updateMovement" );
where %this.updateTime is how often the movement updates in milliseconds,
and "updateMovement" is the name of the function that updates the velocities of my objects.
So, now that you have an object's velocity, acceleration, and time interval, you can modify and update a given object's velocity as much as you like:
newVelocity = oldVelocity + timeInterval * acceleration;
I don't know if this is efficient enough for your project, but it does give you lots of flexibility.
Hope this helps!
12/11/2006 (12:02 pm)
Salutations!I wanted to have a race car accelerate, myself. I ended up managing most of the properties myself instead of using forces in TGB. My simulation was pretty hacky, but it ended up looking excellent (I think). =)
I made a dynamic variable for acceleration (so that I could tweak it around in the editor).
%this.getLinearVelocity() holds our current velocity
A vector variable can be instantiated with:
%myVect = "1.0 0.0 0.0";
To get fields of the vector, use getWord(
%this.setLinearVelocity(getWord(myVect, 0), getWord(myVect,1) );
To keep track of time you can use getSimTime(), or you can just schedule updates at regular time intervals
using the schedule function. For example:
%this.schedule(%this.updateTime, "updateMovement" );
where %this.updateTime is how often the movement updates in milliseconds,
and "updateMovement" is the name of the function that updates the velocities of my objects.
So, now that you have an object's velocity, acceleration, and time interval, you can modify and update a given object's velocity as much as you like:
newVelocity = oldVelocity + timeInterval * acceleration;
I don't know if this is efficient enough for your project, but it does give you lots of flexibility.
Hope this helps!
Torque Owner Thomas Buscaglia
Edit: Spelling.