Animating Shock Spring Issue

Animating Shock Spring Issue

Anonymous
Not applicable
2,301 Views
6 Replies
Message 1 of 7

Animating Shock Spring Issue

Anonymous
Not applicable

Morning, 

First post here after using Max since forever.  I am having an issue animating the sping inside of a shock. The inside of the shock/cylinder has 2 springs, 1 at the top and one at the bottom. Between them is a gap so these springs are only anchored on 1 end and the other end is free. There is a shaft that goes through the center of the shock/cylinder that moves up and down. On the end of the shaft is a small cylinder. When the shaft moves so far upward, the small cylinder compresses the spring and as the shaft moves back downward to its resting position in the middle the spring decompresses. The same happens if the shaft moves down towards the bottom. The lower spring compresses  the shaft end makes contact with the spring and decompresses as the sshaft returns to its resting position. 

I have this sort of working using wire paramters but the problem is that when I move the shaft up or down the springs react even with the shaft end nowhere near the spring. I would like to delat the springs reaction to the movement of the shaft until the shaft end makes contact with or gets close enough to the spring. 

Is this even possible. I looked into expression controllers but I do not have much experience so I am blindly looking at tutorials. 

0 Likes
2,302 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable

Would this be possible using MassFx

0 Likes
Message 3 of 7

leeminardi
Mentor
Mentor

Here's a simple solution using Wire Parameters.

 

In the example below the top of the bottom box is at 0,0,0 and the bottom of the top box is 0,0,100 and therefore the distance between them is 100. The middle box thickness is 2 and its pivot is on the top.    I'll assume the uncompressed height of the spring is 20.

A wire parameter is added to the top spring (spring001) from its Free Spring Height to the Z position of BoxMid.

 

The expression for the top spring is:

 

if (97-Z_Position) > 20 then 20 else (97-Z_Position)

 

and for bottom spring is:

if (Z_Position) > 21 then 20 else (Z_Position-1)

This spring wire diameter is 2.0. 

 

Move BoxMid up and down in the attached file.  All of these object could be linked to a dummy to make the displacements relative to the location and orientation of the dummy.

 

image.png

lee.minardi
0 Likes
Message 4 of 7

Anonymous
Not applicable

Thanks for replying. I will try and set this up again. I went with using a controller. This works perfect until I link the objects to a dummy. Even with using local space it falls apart. I am new to Maxscript so I may be getting the syntax wrong.  Everything moves to crazy positions when linked to a dummy/parent. Works perfect if not parent though.

Here is what I have.   


ta = $topSpringAnchoredEnd
t = $topSpringLooseEnd
m = $shaftEnd

compressionPoint = 30

maxCompressionPoint = 15

decompressionOffset = 25

dist = distance m ta

--print ("Distance From Top Spring Anchor End is " + dist as string)


if dist <= compressionPoint
then
(
 print ("spring is compressing")
 	
	--match the topSpringLooseEnd's Z pos to the shaftEnd's Z pos while in compression range
	in coordsys local t.pos.z = m.pos.z
)
else
(
  print ("spring fully decompressed")
	
	--set the topSpringLooseEnd's Z pos back to the original uncompresed position
  	in coordsys local t.pos.z = ta.pos.z - offset
)
0 Likes
Message 5 of 7

leeminardi
Mentor
Mentor

In the following I have linked all the object to a master dummy.  The calculations are all then done in world coordinates.  The dummy may be positioned anywhere and at any orientation.

 

 

spBottom = $Spring001
spTop = $Spring002
boxmid = $boxMid
maxSpringHeight = 20
dTop = length(spTop.pos- boxmid.pos) - 2
dBot = (length(spBottom.pos - boxmid.pos)) - 2
--format "\n spTop.pos = %, spBottom.pos = % " spTop.pos spBottom.pos 
if dBot <  maxSpringHeight then   spBottom.Free_Spring_Height = dBot 
	else spBottom.Free_Spring_Height = maxSpringHeight
if dTop <  maxSpringHeight then   spTop.Free_Spring_Height = dTop 
	else spTop.Free_Spring_Height = maxSpringHeight

 

lee.minardi
0 Likes
Message 6 of 7

Anonymous
Not applicable

Thanks for your help. I had to do it slightly different because the spring modifier doesn't export out so I skinned the springs using bones. Is there a way to bake these wire animations out as key frames? I am trying to get this stuff out of Max and into Playcanvas but I can't seem to find a direct answer. 

0 Likes
Message 7 of 7

domo.spaji
Advisor
Advisor

Collapse controller for baking on controller level, Point Cache  for baking to simplest, vertex level.

You have to know what you can import to that app.

0 Likes