# 3D collisions on a race track using pre-determined nodes

#### Jex

##### Member
Hello
Thanks so much to anyone reading this post. I've actively been programming and designing in GameMaker for about 7 to 8 years but I cannot recover my other community account so I've made this one to post my issue here.

I'm currently designing a 3D racing game with models imported into GameMaker 8.1 as .d3d.
A design goal is to create track pieces that I can place in the room editor. These track pieces will (upon room_start) create nodes (obj_node) and assign then x,y,z coordinates that will coincide with the track piece's furthest corners, lowest z values and highest z values. I hope that I've explained that sufficiently.

The issue I'm having is somewhat with collision detection for the obj_car. I am able to detect if the car is at the lowest or highest z value on a track using the following:
Code:
``````node_1 = instance_nearest(x,y,obj_node) // closest node
node_2 = instance_nearest(x+lengthdir_x(20,direction),y+lengthdir_y(20,direction),obj_node) // closest node that the car is facing

// 3D Line
highest = max(node_1.z,node_2.z) // returns the node with the highest z value
lowest = min(node_1.z,node_2.z) // returns the node with the lowest z value
inc = angle_difference(node_1.z,node_2.z) // returns the difference in z values between the two nodes
l1 = point_distance_3d(x,y,z,node_1.x,node_1.y,node_1.z) // distance to the first node in 3D
l2 = point_distance_3d(x,y,z,node_2.x,node_2.y,node_2.z) // distance to the second node in 3D``````
What I would like to achieve is some kind of code that will find the car's position between the variables highest and lowest and appropriately return the car's z position as an even division of the two heights (I think). I've struggled with this trying lots of things such as "z = mean(highest,lowest)" which just placed the car directly between any two nodes and didn't allow for a smooth incline or decline. I would really really love to be able to figure out also how to have the car rotate to appear to sit properly on the 'slope' between two nodes as well to be able to be drawn with x and y rotations via d3d_transform_add_rotation_ (x/y/z) etc.
I'm using nodes with predetermined values as I couldn't think of another way to do 3D collisions with slopes and ramps/bumps in the road.

I hope I've explained this okay and I thank anyone in advance for any suggestions or ideas or anything

Jex.