Brake lights on when car stops/ off when moves

Brake lights on when car stops/ off when moves

coilbookmedia
Advocate Advocate
1,434 Views
6 Replies
Message 1 of 7

Brake lights on when car stops/ off when moves

coilbookmedia
Advocate
Advocate

Hi anyway to create a wiring parameter for blend texture where if object moves brake lights are off when slows down or stops blend material value changes to 100 making lights on.

We will have a lot of cars in the scene that will randomly stop and go  and animating brake lights for each one is impossible, 

The scene is attached.  Thank you! 

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

coilbookmedia
Advocate
Advocate

i found this example where car follows the path and if it stops material id changes. Anyway to have if car changes position at all it will change material id  not just percentage path constraint?  We will be using city traffic plugin and there is not follow path just movement of mesh.   Thank you 

 

Anyway t ochange 

 

Current Script Controller position.controller.percent  to actual mesh movement in space XYZ  to trigger lights off and on

 

 

braking = .96

theCar = $MaroonSedan
PositionNext = at time (currentTime + 1) theCar.position.controller.percent
PositionCurrent = at time currentTime ( theCar.position.controller.percent )
PositionPrevious = at time (currentTime - 1) ( theCar.position.controller.percent )

travel = abs (PositionNext - PositionCurrent)
travelPrev = abs (PositionCurrent - PositionPrevious)

--ID = 1

if (travel <= 0.01) then (ID = 2 ) -- standing still
--else (

else if ((travel / travelPrev) < braking) then ( ID = 2 ) -- braking
else( ID = 1 ) -- coasting

--)

 

0 Likes
Message 3 of 7

leeminardi
Mentor
Mentor

I created a Max file with a box that moves along at a constant speed and then slows down.  The file also contains a point object and a light.

 

The following script assigned to the point's y position will move it to 1 in Y if boxA is slowing down and 0.0 if is not.  I had hoped to use this as the switch to turn the light on/off.  I tried assigned the variable bLight to the intensity of the light object but it did not change when tested.  I also tried wiring the intensity of the light to the position of the point but that had no effect either.  I am at a loss as to how to associate the light's intensity or multiplier to a script variable.   

 

braking = 0.96
car = $BoxA
posNow = at time (currentTime) car.position
posNext = at time (currentTime + 1) car.position
posBefore = at time (currentTime - 1) car.position

dPre=length(posNow-posBefore)
dNext=length(posNow-posNext)

if(abs(dPre-dNext) <= 0.01) then 
 (bLight = 0.0
  0.0
  ) -- standing still
else if ((dNext/dPre) < braking) then 
(bLight = 1
1.0
)
else 0.0

lee.minardi
Message 4 of 7

coilbookmedia
Advocate
Advocate

Thank you! 

0 Likes
Message 5 of 7

coilbookmedia
Advocate
Advocate

By the way is there any way to apply this to multiple cars automatically? or have lights work with the car they linked to? instead of  changing this for each light  and car  since we will have hundreds of cars.   car=$BoxA   something like  car = the one where lights linked to? 

 

Our best goal is to actually use octane mix texture instead of material id change  but not sure how this can be done  

 

 

Thank you  

0 Likes
Message 6 of 7

leeminardi
Mentor
Mentor

I'm fairly new to Max scripts so it might be better to post your question on the Programming forum.

 

I think one approach you could take to cycle through all you cars and their brake light is via a object naming convention.  For example, CarV01, CarV02, .. would be the names for the vehicle while CarB01, CarB02,... would be the names for the corresponding brakelights. A script could cycle through all the objects that start with "CarV" and determine if it is braking or not.  The script would then look for the object "CarB" concatenated with the number of the current car.  I am not sure if you can do this with a Max script. Alternatively, there may be a way to look for linked objects once the car is found.

 

Good luck.  

lee.minardi
0 Likes
Message 7 of 7

faline.custodio.da.silva
Alumni
Alumni

@coilbookmedia

 

Thanks for posting! I would agree with @leeminardi you should post in the 3ds Max Programming forum. The folks there are very knowledgeable and should be able to help you out!

 

Cheers!

 


Faline Custodio Da Silva

0 Likes