Skip to main content

Cars along spline

Overview

We recently released a tutorial on how to use Forest Pack to scatter cars. In this we discussed the best way to place pivots and paths, and the final scene used splines that were placed through the centre of the car parks so that we could use the mirror and offset features to create parked cars facing in either direction.

You may however already have a spline at the top of the car park that you wish to re-use. Normally this would mean you couldn't mirror the car but with Forest Effects we can now easily extend the plugin to make this possible.

This Car Parking effect allows you to use a spline at the top or bottom of the parking bay and the vehicles are automatically offset along their length to fit into the space. In addition, it also randomises the car's position along its local axis and add controls to make it easier to adjust the probability of spaces and choose which side of the spline the cars should be positioned on. You can also randomise the direction of the cars by rotating through 180 degrees instead of flipping the car which removed any issues of left and right hand drive cars and mirrored number plates and logos. To use it, set up the cars as described in the tutorial with the pivot in the centre of the car. Place the cars using Tree Editor > Creation Tools > Along a Path is normal and then adjust the following parameters:

  • Use switchSides to move all the cars from one side of the path to the other
  • Use emptySpaces to change the probability of empty parking spaces
  • Use randomiseParkDirection to randomise whether cars are parked bonnet of boot first in each space.
  • Use xOffsetStart to set a minimum X translation value, in scene units.
  • Use xOffsetEnd to set a maximum X translation value, in scene units.
  • Use YOffsetStart to set a minimum Y translation value, in scene units.
  • Use YOffsetEnd to set a maximum Y translation value, in scene units.

Effect Script

real angle = fpItem.rotation.z;
fpItem.rotation.z =fpItem.rotation.z + if(randomInt(0,randomiseParkDirection)==1,degtorad(180),0);
real randomOffsetX = randomInt(xoffsetStart,xoffsetEnd);
real randomOffsetY = randomInt(YoffsetStart,YoffsetEnd);
vector position = [cos(angle)*(fpItem.collisionRadius+randomoffsetX), sin(angle)*(fpItem.collisionRadius+randomoffsetX),0];
position = position + [cos(angle-degtorad(90))*(randomOffsetY), sin(angle-degtorad(90))*(randomOffsetY),0];
fpItem.position = if(switchSides==0,fpItem.position+position, fpItem.position-position);
int spaceProbability = randomInt(1,100);
fpItem.visible = if(emptySpaces >= spaceProbability,0,1);

You can find this Effect within the Forest Effects Library .

This Effect Uses

Parameters

  • YOffsetStart

Type: Scene Units

  • YOffsetEnd

Type: Scene Units

  • YOffsetStart

Type: Scene Units

  • YOffsetEnd

Type: Scene Units

  • switchSides

Type: Int (0 is off, 1 is on)

  • emptySpaces Type: Int
  • randomiseParkDirection Type: Int (0 is off, 1 is on)

Attributes

  • fpItem.position

Position vector of individual fp Item.

  • fpItem.rotation.z

Individual item's Z rotation.

  • fpItem.visible

Individual item's visibility

  • fpItem.collisionRadius

The collision radius of the item. Measured as a sphere whose diameter matches the size of the object's largest dimension.

Functions

  • randomInt

Returns an integer random number in the range

a,b

  • degToRad(p)

Converts degrees to radians.

  • cos(p)

Cosine of p (p expressed in radians)

  • sin(p)

Sine of p (p expressed in radians)