Re: RES: breve Digest, Vol 20, Issue 8
jon klein <[email protected]> Wed, 23 Mar 2005 10:29:33 -0500
| Newsgroups | gmane.comp.breve |
|---|---|
| Message-ID | <[email protected]> |
On Mar 22, 2005, at 8:04 PM, Willian Filus wrote:
> Hi John,
>
> This is a simple sample of a simulation, I would like to move the red
> cube
> with a mouse click to other object (blue sphere), I can move it, but I
> would
> like to move it slowly, until the object are selected.
Hi Willian,
the method "move" is used to move an object instantaneously. If you
want to move an object more slowly, you need to use "set-velocity".
Because you want the Car object to move slowly towards its target, I've
added in a "goal" variable to the Car class. Whenever the goal is set
to a location in the world, the car will move slowly towards that goal.
Note that you will also have to replace the "car move to (item
get-location)" with "car set-goal to (item get-location)" in your
"click" method.
Mobile : Car (aka Cars) {
+ variables:
goal (vector).
+ to set-goal to newGoal (vector):
goal = newGoal.
+ to init:
self set-shape to (new Cube init-with size (0.5,0.5,0.5)).
self set-color to (1,0,0).
+ to iterate:
diff (vector).
diff = goal - (self get-location).
if |diff| > 0.01: {
self set-velocity to .2 * diff / | diff |.
} else {
self set-velocity to (0, 0, 0).
}
}
- jon klein
_______________________________________________
breve mailing list
[email protected]
http://lists.spiderland.org/mailman/listinfo/breve