Notifications
Clear all

[Closed] Float Script for Brake Lights along a path constraint

Whats up guys, working on a project animating some cars along paths.

So the client wants to add brake lights to the cars, which I figure I’ll implement by animating the Self Illumination in the cars’ material.

This works, but would be a pain to do for a whole traffic jam.

So I’m wondering if it’s possible to tie the “speed” (which is really just the percentage based progression along the path) of the car to the value of the self illumination in the material. So when that percentage gets low enough, the brake lights illuminate.

Now this might be fantastic idea, but I have absolutely no idea how to make this happen. Anyone have a tutorial, suggestion, or even be interested in creating something like this for paying work? Naturally we’d discuss the number, but this would save a lot of time so I think its worth it.

Thanks,
Ryan

13 Replies

you could tie the speed to the selfIllumination, but you need braking – not speed.

You need to get three positions at three different points in time. With those you can determine whether the car is…
standing still / going forward / going backwards
coasting / accelerating / decelerating (braking)

Example script controller code:


  acceleration = 1.09
  braking = 0.9
  
  theCar = $GeoSphere01
  nextPos = at time (currentTime + 1) theCar.pos
  curPos = at time currentTime ( theCar.pos )
  prevPos = at time (currentTime - 1) ( theCar.pos )
  
  travel = distance nextPos curPos
  travelPrev = distance curPos prevPos
  travelDir = (ray nextPos (nextPos - curPos)).dir
  
  r = 0
  g = 0
  b = 0
  
  if (travel == 0) then (  ) -- standing still
  else (
  	if ((dot theCar.dir travelDir) < 0) then ( r = 0.25; g = 0.25; b = 0.25 ) -- reversing
  	if ((travel / travelPrev) < braking) then ( r = 1 ) -- braking
  	else if ((travel / travelPrev) > acceleration) then ( b = 1 ) -- accelerating
  	else ( r = 0.25 ) -- coasting
  )
  [r,g,b]
  

( Note: I’m in max5 at the moment – in later versions you can make ‘theCar’ a nice variable instead of a reference to an absolute value, making it much easier to set it up on multiple objects as well. )

See attachment for a sample file.

Edit: obviously, this is a Color Script controller. If all you need is self-illumination for braking, you can do so with a Float Script controller, and ignore any of the items not related to braking.

Edit2: Forward/reverse depends on the car’s ‘direction’, i.e. its local Z axis. If it’s using a different axis, you’ll have to adjust accordingly. You mentioned using path controllers, so you could actually determine whether it’s moving forward/backward much more easily, simple check if its percentage along the path is greater or smaller between two points in time. The above code is a bit more generic.

That’s an awesome start ZeBoxx2; but I am truly a beginner at Scripting. I opened the file and in an effort to dig deeper into the script I’d like to mess around with some values in max, but I can’t even find where/how that script is applied.

How do I access that script and change the values around. I thought it would be in a Float Script controller but I can’t seem to find it…

Thanks,
Ryan

It’s on the pointy sphere’s material’s diffuse color track

Alright got that, now I’m starting to test the script.

I think it should be a relatively easy transfer over to a Path Constraint; here’s what I have:

acceleration = 1.09
  braking = 1
  
  theCar = $Box01
  nextPos = at time (currentTime + 1) theCar.pos.controller.percent
  curPos = at time currentTime ( theCar.pos.controller.percent )
  prevPos = at time (currentTime - 1) ( theCar.pos.controller.percent )
  
  travel = distance nextPos curPos
  travelPrev =  distance curPos prevPos
  
  r = 0
  g = 0
  b = 0
  
  if (travel == 0) then (  ) -- standing still
  else (
	  
	  if ((travel / travelPrev) < braking) then ( r = 1 ) -- braking
	  
	  else ( r = 0.25 ) -- coasting
  )
  [r,g,b]
  

It’s not working though. I need the equivalent for distance in regards to the path constraint…anything else look incorrect?

the path controller’s percentage is a float value (e.g. 1.0, 10.2, 0.23, -0.8, etc.), while distance works with point3 values (e.g. [0,0,0], [1,2,3], [-1,3,-2], etc.).

The equivalent for floats would be:


travel = abs (nextPos - curPos)
travelPrev =  abs (curPos - prevPos)

One thing to keep in mind is that, if “constant velocity” is off in the path controller, then the actual speed along the path will depend on the distance between knots in your path spline. So the difference beteen 0% to 1% and 1% to 2% is not necessarily the same in that case.
Easiest solution for that is to make sure you -are- using “constant velocity”. If you’re not, there’s further calls in 3ds Max that help you get the actual distance along a path given a percentage value… but we can get to that if that applies and “constant velocity” is not an option

Thats awesome Zeboxx2 the script is working without any errors, but I’m not sure if I need to further adjust that script as far as constant velocity…

I am using Constant Velocity, but I applied a Bezier Float to the Percent value of my Car. This way it graduallys slows down along the path, based on custom tangents on the keyframes. So constant velocity is checked, but it does slow down and speed up along the path so it really isn’t constant velocity…

The only issue with it now as that I can’t seem to get that perfect value where the brake turns on as soon as it slows down, its always a before or once it’s practically stopped. (based on changing the braking value)

EDIT: I also can’t figure out how to modify this script to set the amount of Self Illumination. I deleted the old script from the diffuse, and addeda float script controller to the Self Illumination. Then I added this code, but I keep getting an “Unable to Convert: Undefined to type: Float” error…

braking = .96
  
  theCar = $Box01
  nextPos = at time (currentTime + 1) theCar.position.controller.percent
  curPos = at time currentTime ( theCar.position.controller.percent )
  prevPos = at time (currentTime - 1) ( theCar.position.controller.percent )
  
  travel = abs (nextPos - curPos)
  travelPrev =  abs (curPos - prevPos)
  
  selfIllumAmount = 0
  
  if (travel == 0) then (  ) -- standing still
  else (
	  
	  if ((travel / travelPrev) < braking) then ( selfIllumAmount = 100 ) -- braking
	  
  )

  

Ryan

Yeah, the wording of that control is a bit confusing. It doesn’t mean that your object is moving at a constant speed along the path in general, just that no matter how far points are placed along a spline, it will always move the same distance for the same given percentage.

See the attached file for a basic example showing the difference.

If you want it as soon as it slows down, the braking value should just be 0.99 or so.

If you want to have it turn on the brake light on the frame it slows down (it currently does it just before; after all, you have to brake first – then the car slows down, not the other way around), change bits to this:


   nextPos = at time currentTime theCar.position.controller.percent
   curPos = at time (currentTime - 1) ( theCar.position.controller.percent )
   prevPos = at time (currentTime - 2) ( theCar.position.controller.percent )
   

The terminology “nextPos” will be invalid, but you can rename those if you want

That’s because currently, if it’s not braking, you’re not returning any value…
Change…


if ((travel / travelPrev) < braking) then ( selfIllumAmount = 100 ) -- braking
else ( selfIllumAmount = 0 ) -- coasting

I hope that helps

Thats amazing ZeBoxx2, I really can’t thank you enough for all the help.

The last little bump I’m hitting is that I can’t set a specific amount For Self Illumination, it’s just coming back as 0 or 100.

I modified the code to say:

if ((travel / travelPrev) < braking) then ( selfIllumAmount = 60 ) -- braking

And it still goes from 0 to 100…no in betweens.

Almost like it’s returning a true/false value but not a specific amount…

1 Reply
(@zeboxx2)
Joined: 11 months ago

Posts: 0

Sometimes parameters in 3ds Max bits and pieces are funky. They display as one thing, but internally they’re another.

In this case, the parameter displays as 0 through 100, but internally it uses the values 0.0 through 1.0

So instead of ‘60’, use ‘0.6’.

You can often tell what a parameter expects when you assign the scripted controller. The default script expression will have the values shown as the parameter stores them internally.

look what i found today… http://www.xn–d1abb4ane.com/blog/archives/77 ( don’t forget to see the video…link above the picture )

edit: forgot… http://www.рендер.com/blog/archives/68

Page 1 / 2