PDA

View Full Version : MAXscript? velocity, acceleration / deceleration


Ian Jones
10-12-2002, 03:34 AM
Hi there.

Question for any MAXscript guru's out there...

I want to make an object lets say a box, follow another box's position. Instead of the default link which makes a movement ratio of 1:1 I want to make the following box slower as it nears the leading box. Like deceleration. I want it to sample the distance difference between box A and Box B and move box B closer 10% of the difference per sample. Say a sample is every second or every frame or whatever. So if the difference was 100 units then box B would move 10 units towards box A, assuming that box A is now sationary at the next sample box B would move 10% of the difference which is now 90 units since the last sample. So Box B moves 9 units and the difference at the third sample is now 81 units and it goes on until the box B decelerates 10% each sample and finally comes to a stop in the same postion as box A. Thus simulating deceleration.

In Macromedia Flash MX I would make a ball (like box B) follow the mouse (the controller object like box A) with an actionscript as attached in the example file I have provided.

Can this be done with MAXscript? I would love to see an example file as it is great for removing the usual static type of movement interaction between objects. For example you can use it in Flash to make a car body follow a car chassis but with a little bit of lag between the two which makes it look like it is being affected by g-forces of acceleration and the spring of the suspension when turning corners or stopping suddenly.

I hope someone can help. I'm a complete newb to MAXscript.

Thx in advance. :)

Ian Jones
10-13-2002, 01:01 AM
*bump*

Ian Jones
10-14-2002, 07:04 AM
*bump*

I have another question aswell, unrelated to any scripting. (may aswell talk to myself in the same thread) :)

How would I make a mesh of the earth? I have made a sphere and added a map to it, transparency included but how would I extrude this on the surface? and remove the original sphere leaving a thin crust of the continents minus the sea, so it is hollow.

Any ideas?

Clanger
10-14-2002, 02:32 PM
A long time ago I needed to make a continent only world, using Max ver. 1. I put a massive bump on the material and stacked about 5 spheres together this gave a good illusion of solid geometry.

Ian Jones
10-15-2002, 12:38 AM
Thx, I will try that. Not sure whether it will work for me in the long run because I need to have some geometry to affect a volume light casting from within the globe.

Thx for your reply.

toonman
10-15-2002, 01:27 AM
Originally posted by Ian Jones
Hi there.

Question for any MAXscript guru's out there...

I want to make an object lets say a box, follow another box's position. Instead of the default link which makes a movement ratio of 1:1 I want to make the following box slower as it nears the leading box. Like deceleration. I want it to sample the distance difference between box A and Box B and move box B closer 10% of the difference per sample. Say a sample is every second or every frame or whatever. So if the difference was 100 units then box B would move 10 units towards box A, assuming that box A is now sationary at the next sample box B would move 10% of the difference which is now 90 units since the last sample. So Box B moves 9 units and the difference at the third sample is now 81 units and it goes on until the box B decelerates 10% each sample and finally comes to a stop in the same postion as box A. Thus simulating deceleration.


Yes, this can be scripted. However, it's not as easy, for reasons I explained in a different post somewhere.
Speed is a relationship between the distance travelled by an object, and the time it gets to travel that distance. Given that, it could be possible to sort of script a spring, which is what you want, that follows an object, but damps when it enters within a certain distance threshold from the named object, and that will start accelerating again as it goes beyond a certain distance. I'd have to start doing some math here to get this script controller working (yes, I'd do a script controller applied to the position track). However, there's an easier solution... the spring controller... it'll do exactly what you need.


In Macromedia Flash MX I would make a ball (like box B) follow the mouse (the controller object like box A) with an actionscript as attached in the example file I have provided.

Can this be done with MAXscript? I would love to see an example file as it is great for removing the usual static type of movement interaction between objects. For example you can use it in Flash to make a car body follow a car chassis but with a little bit of lag between the two which makes it look like it is being affected by g-forces of acceleration and the spring of the suspension when turning corners or stopping suddenly.

I hope someone can help. I'm a complete newb to MAXscript.

Thx in advance. :)
You could do the whole ball thing using motion capture controllers in max, and your mouse. As for the car, I'd do the same... position spring controllers. Hope it helps! Cheers!

Ian Jones
10-15-2002, 02:30 PM
Hi there,

Thx for your reply. I will investigate the spring controllers. It's gonna be hard though cos I'm new to 3d. I'll give your suggestion a go.

Did you download the example Flash MX file? It illustrates exactly how I want the motion to behave. Move your mouse around and the ball will follow it. The faster you move the mouse around the further the distance the ball is lagging behind. If you suddenly stop the ball with decelerate towards the mouse position 10% of the distance difference per frame which I think in this case is 20 frames per seconds. So its moving 10% of the distance difference every 1/20th of a second. You can even see the actionscript I have included with the sourcefile. You'll need to know how to use Flash MX to understand it.

The one problem I can imagine with a spring is that it will let the object fly past and spring from side to side eventually stopping. I would love to know how to do this too, but for now I want to figure out the original idea.

Anyone have any more ideas? I'd love for an example file if possible. :) haha.

toonman
10-15-2002, 07:16 PM
Originally posted by Ian Jones
Hi there,

The one problem I can imagine with a spring is that it will let the object fly past and spring from side to side eventually stopping. I would love to know how to do this too, but for now I want to figure out the original idea.

Anyone have any more ideas? I'd love for an example file if possible. :) haha.


Hmmm... you're right on this one... that's what the spring controller would do... I don't know Flash, so I wouldn't know about the action script (If I could open it, maybe I could understand what's going on there). This is doable with script controllers, but it won't be as easy, since the relationship between the nodes is not linear... lemme see if I can work something out... interesting problem (the thing is I'm swamped with work right now, but I'll see if I can give it a go). Cheers!

LFShade
10-15-2002, 08:47 PM
This would be almost trivial if only there were a 'self' accessor for script controllers. Not being able to self-reference in script and expression controllers is a real bummer when you need to do something like this :(

Ian Jones
10-16-2002, 06:49 AM
Heh, sorry you couldnt open it (it is in native Flash MX format *.fla. You should check this post at the bottom for an new file, it is a *.swf run it and it should just play for you to see the effect. If you can see the Zbrush ad at the top of this page then you should have the Flash6 player already installed.

Toonman: Don't neglect your work... :) it'd be great if you could though. Make sure you check the example file to make sure you don't do the wrong thing and waste time.

LFShade: Pity it doesn't, I would have thought that to be almost a standard practice in all programming languages. :( It is really easy with Flash, you just call a property like this sorta thing... ball._x = _xmouse
ball._y = _ymouse

That really tiny script will make the ball object move its x and y to the x and y of the mouse. So the ball follows the mouse exactly. It is a little more complex to do the deceleration though. Like this...

ball._x+=(_root._xmouse-ball._x)*0.1;
ball._y+=(_root._ymouse-ball._y)*0.1;

That += sign means A+B = the new value of A, and updates the value of A after the equation. Ignore the _root thingy that is just the base level of the movie. Hopefully what you can see here though is that the difference is tested _xmouse minus ball._x gives you the difference, which is then multiplied by 0.1 to make it only move 10% of the difference, same for the y coordinates. Thats how the deceleration works.)

I hope that made sense. Example *.swf attached.

xyth
11-25-2002, 08:31 AM
Hiya,

It could be I'm a little bit late, but I know a more simple solution.
Use flex to do its job. It's just perfectly does this even with oscillation, if you wish.

So, make a box01 and a box02. Link box02 to box01. Give a flex modifier to box02. Animate box01 translations, rotation and watch. If you don't like its damping, oscillation, whatever, play with the parameters of flex.

I wrote this only by heart, so If it doesn't work and you cannot figure out just write and I make a scene set-up for you.

You can make burnout trails, flags, even moving liquids ( http://www.cgtalk.com/showthread.php?s=&threadid=27355&highlight=flyhigh )

-xyth

Ian Jones
11-25-2002, 12:39 PM
Hi. Your not too late. I thought this thread was condemed for all eternity, so thanks for letting me know about your flex modifier method! :)

I gave it a go, but all I could get it to do was follow the box01 and the box02 did nothing but go absolutely crazy changing shape and gong wild.

Could you please make a simple scene for me? Perhaps a small walkthru of the steps you took to get it that way too. I would really appreciate this as I am new to 3D so I need every piece of direction I can get. Thx.

Clanger
11-25-2002, 01:04 PM
I gave the flex method a try and I think it will work, just turn off use weights and increase the sway (around 80 looked good)

xyth
11-26-2002, 07:02 AM
So, here are the files. A flex and a spring solution. (Am I sending spring to Australia? Hahh... It's there already!)

It is self-explaining, it is made almost with default values.
At flex, experience the Flex and Sample values first. Than the rest. :) Yes, weights turned off.
At spring the Weight is the "main" parameter.

About the script: it is different as in flash. Thing about that if you want to use those mentioned expressions, than it will mean that you want to calculate the active position by using the active position... In flash the code runs first, but there is a basic default x;y value for an object. In max you give it with this script. So what to do? To press OK for "Illegal expression" alertbox. ;)
-xyth

xyth
11-26-2002, 07:02 AM
So, here are the files. A flex and a spring solution. (Am I sending spring to Australia? Hahh... It's there already!)

It is self-explaining, it is made almost with default values.
At flex, experience the Flex and Sample values first. Than the rest. :) Yes, weights turned off.
At spring the Weight is the "main" parameter.

About the script: it is different as in flash. Thing about that if you want to use those mentioned expressions, than it will mean that you want to calculate the active position by using the active position... In flash the code runs first, but there is a basic default x;y value for an object. In max you give it with this script. So what to do? Press OK for "Illegal expression" alertbox. ;)
-xyth

xyth
11-26-2002, 07:32 AM
Repeating is the mother of all knowledge. Repeating is the mother of all knowledge. Repeating is the mother of all knowledge... Sorry.

Ian Jones
11-26-2002, 08:17 AM
hehe. thx dude. :)

I'll take a closer look at the follow_flex file after dinner... thx once again.

And... well I dunno what to say about the follow_spring. :)

xyth
11-26-2002, 10:19 AM
Good apetite,

At follow_spring check the position controller which is no longer a bezier controller as a default but spring controller. Right click on it, check Properties.

-xyth

CGTalk Moderation
01-13-2006, 07:00 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.