├── .gitignore ├── Assets ├── 3D Vehicle Pack.meta ├── 3D Vehicle Pack │ ├── Vehicles.meta │ └── Vehicles │ │ ├── Sports_car.meta │ │ └── Sports_car │ │ ├── Materials.meta │ │ ├── Materials │ │ ├── car_body_txtr.mat │ │ └── car_body_txtr.mat.meta │ │ ├── car_body_txtr.png │ │ ├── car_body_txtr.png.meta │ │ ├── sports_car.fbx │ │ └── sports_car.fbx.meta ├── Low_Poly_Sport_Car_ME_R4.meta ├── Low_Poly_Sport_Car_ME_R4 │ ├── CC_ME_R4.FBX │ ├── CC_ME_R4.FBX.meta │ ├── Materials.meta │ └── Materials │ │ ├── CC_ME_Body_R4.mat │ │ ├── CC_ME_Body_R4.mat.meta │ │ ├── CC_ME_Body_R4.png │ │ ├── CC_ME_Body_R4.png.meta │ │ ├── CC_ME_Wheels_R4.mat │ │ ├── CC_ME_Wheels_R4.mat.meta │ │ ├── CC_ME_Wheels_R4.png │ │ └── CC_ME_Wheels_R4.png.meta ├── Materials.meta ├── Materials │ ├── Asphalt.mat │ └── Asphalt.mat.meta ├── Prefabs.meta ├── Prefabs │ ├── Vehicle1.prefab │ ├── Vehicle1.prefab.meta │ ├── Vehicle2.prefab │ └── Vehicle2.prefab.meta ├── Scenes.meta ├── Scenes │ ├── Example1.unity │ ├── Example1.unity.meta │ ├── Example2.unity │ └── Example2.unity.meta ├── Scripts.meta ├── Scripts │ ├── Controller.cs │ ├── Controller.cs.meta │ ├── FollowTarget.cs │ ├── FollowTarget.cs.meta │ ├── PlayerCar.cs │ ├── PlayerCar.cs.meta │ ├── RaycastWheel.cs │ ├── RaycastWheel.cs.meta │ ├── RaycastWheelSimple.cs │ └── RaycastWheelSimple.cs.meta ├── Textures.meta └── Textures │ ├── asphalt.jpg │ └── asphalt.jpg.meta ├── ProjectSettings ├── AudioManager.asset ├── ClusterInputManager.asset ├── DynamicsManager.asset ├── EditorBuildSettings.asset ├── EditorSettings.asset ├── GraphicsSettings.asset ├── InputManager.asset ├── NavMeshAreas.asset ├── NetworkManager.asset ├── Physics2DSettings.asset ├── ProjectSettings.asset ├── ProjectVersion.txt ├── QualitySettings.asset ├── TagManager.asset ├── TimeManager.asset ├── UnityAdsSettings.asset └── UnityConnectSettings.asset └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # =============== # 2 | # Unity generated # 3 | # =============== # 4 | Temp/ 5 | Obj/ 6 | UnityGenerated/ 7 | Library/ 8 | Builds/ 9 | 10 | # ===================================== # 11 | # Visual Studio / MonoDevelop generated # 12 | # ===================================== # 13 | ExportedObj/ 14 | *.svd 15 | *.userprefs 16 | *.csproj 17 | *.pidb 18 | *.suo 19 | *.sln 20 | *.user 21 | *.unityproj 22 | *.booproj 23 | 24 | # ============ # 25 | # OS generated # 26 | # ============ # 27 | .DS_Store 28 | .DS_Store? 29 | ._* 30 | .Spotlight-V100 31 | .Trashes 32 | Icon? 33 | ehthumbs.db 34 | Thumbs.db 35 | -------------------------------------------------------------------------------- /Assets/3D Vehicle Pack.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 220ed5aaf3f3b4e01941609e048ce71b 3 | folderAsset: yes 4 | timeCreated: 1459961588 5 | licenseType: Store 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/3D Vehicle Pack/Vehicles.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7deb33bf48eda48afb1c77f337838fa8 3 | folderAsset: yes 4 | timeCreated: 1460566344 5 | licenseType: Store 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/3D Vehicle Pack/Vehicles/Sports_car.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b967d8897317044299b0cebdbb1285cf 3 | folderAsset: yes 4 | timeCreated: 1460822120 5 | licenseType: Store 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/3D Vehicle Pack/Vehicles/Sports_car/Materials.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 56de390cbaad44476897f30e54d16b7b 3 | folderAsset: yes 4 | timeCreated: 1460822147 5 | licenseType: Store 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/3D Vehicle Pack/Vehicles/Sports_car/Materials/car_body_txtr.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity-car-tutorials/SimpleRaycastVehicle-Unity/bc512747091fbbef100b2e7be3bce3ac1aec2cec/Assets/3D Vehicle Pack/Vehicles/Sports_car/Materials/car_body_txtr.mat -------------------------------------------------------------------------------- /Assets/3D Vehicle Pack/Vehicles/Sports_car/Materials/car_body_txtr.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4a390326100e148099d372c3fa931434 3 | timeCreated: 1460822147 4 | licenseType: Store 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/3D Vehicle Pack/Vehicles/Sports_car/car_body_txtr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity-car-tutorials/SimpleRaycastVehicle-Unity/bc512747091fbbef100b2e7be3bce3ac1aec2cec/Assets/3D Vehicle Pack/Vehicles/Sports_car/car_body_txtr.png -------------------------------------------------------------------------------- /Assets/3D Vehicle Pack/Vehicles/Sports_car/car_body_txtr.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ff2ad256ebfa54090a83cb7c5f407654 3 | timeCreated: 1460822146 4 | licenseType: Store 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 2 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 1 11 | linearTexture: 0 12 | correctGamma: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 0 25 | cubemapConvolution: 0 26 | cubemapConvolutionSteps: 7 27 | cubemapConvolutionExponent: 1.5 28 | seamlessCubemap: 0 29 | textureFormat: -1 30 | maxTextureSize: 2048 31 | textureSettings: 32 | filterMode: -1 33 | aniso: -1 34 | mipBias: -1 35 | wrapMode: -1 36 | nPOTScale: 1 37 | lightmap: 0 38 | rGBM: 0 39 | compressionQuality: 50 40 | allowsAlphaSplitting: 0 41 | spriteMode: 0 42 | spriteExtrude: 1 43 | spriteMeshType: 1 44 | alignment: 0 45 | spritePivot: {x: 0.5, y: 0.5} 46 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 47 | spritePixelsToUnits: 100 48 | alphaIsTransparency: 0 49 | textureType: -1 50 | buildTargetSettings: [] 51 | spriteSheet: 52 | sprites: [] 53 | outline: [] 54 | spritePackingTag: 55 | userData: 56 | assetBundleName: 57 | assetBundleVariant: 58 | -------------------------------------------------------------------------------- /Assets/3D Vehicle Pack/Vehicles/Sports_car/sports_car.fbx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity-car-tutorials/SimpleRaycastVehicle-Unity/bc512747091fbbef100b2e7be3bce3ac1aec2cec/Assets/3D Vehicle Pack/Vehicles/Sports_car/sports_car.fbx -------------------------------------------------------------------------------- /Assets/3D Vehicle Pack/Vehicles/Sports_car/sports_car.fbx.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2dae2b82b97304d07b39285c02f67320 3 | timeCreated: 1460822147 4 | licenseType: Store 5 | ModelImporter: 6 | serializedVersion: 19 7 | fileIDToRecycleName: 8 | 100000: //RootNode 9 | 100002: SportsCar_Back_light01 10 | 100004: SportsCar_Back_light02 11 | 100006: SportsCar_Backlight03 12 | 100008: SportsCar_Backlight04 13 | 100010: SportsCar_Car_body 14 | 100012: SportsCar_L_back_wheel 15 | 100014: SportsCar_L_front_wheel 16 | 100016: SportsCar_R_back_wheel 17 | 100018: SportsCar_R_front_wheel 18 | 400000: //RootNode 19 | 400002: SportsCar_Back_light01 20 | 400004: SportsCar_Back_light02 21 | 400006: SportsCar_Backlight03 22 | 400008: SportsCar_Backlight04 23 | 400010: SportsCar_Car_body 24 | 400012: SportsCar_L_back_wheel 25 | 400014: SportsCar_L_front_wheel 26 | 400016: SportsCar_R_back_wheel 27 | 400018: SportsCar_R_front_wheel 28 | 2300000: SportsCar_Back_light01 29 | 2300002: SportsCar_Back_light02 30 | 2300004: SportsCar_Backlight03 31 | 2300006: SportsCar_Backlight04 32 | 2300008: SportsCar_Car_body 33 | 2300010: SportsCar_L_back_wheel 34 | 2300012: SportsCar_L_front_wheel 35 | 2300014: SportsCar_R_back_wheel 36 | 2300016: SportsCar_R_front_wheel 37 | 3300000: SportsCar_Back_light01 38 | 3300002: SportsCar_Back_light02 39 | 3300004: SportsCar_Backlight03 40 | 3300006: SportsCar_Backlight04 41 | 3300008: SportsCar_Car_body 42 | 3300010: SportsCar_L_back_wheel 43 | 3300012: SportsCar_L_front_wheel 44 | 3300014: SportsCar_R_back_wheel 45 | 3300016: SportsCar_R_front_wheel 46 | 4300000: SportsCar_Car_body 47 | 4300002: SportsCar_L_front_wheel 48 | 4300004: SportsCar_R_front_wheel 49 | 4300006: SportsCar_R_back_wheel 50 | 4300008: SportsCar_L_back_wheel 51 | 4300010: SportsCar_Backlight03 52 | 4300012: SportsCar_Backlight04 53 | 4300014: SportsCar_Back_light02 54 | 4300016: SportsCar_Back_light01 55 | 9500000: //RootNode 56 | materials: 57 | importMaterials: 1 58 | materialName: 0 59 | materialSearch: 1 60 | animations: 61 | legacyGenerateAnimations: 4 62 | bakeSimulation: 0 63 | resampleRotations: 1 64 | optimizeGameObjects: 0 65 | motionNodeName: 66 | animationImportErrors: 67 | animationImportWarnings: 68 | animationRetargetingWarnings: 69 | animationDoRetargetingWarnings: 0 70 | animationCompression: 1 71 | animationRotationError: 0.5 72 | animationPositionError: 0.5 73 | animationScaleError: 0.5 74 | animationWrapMode: 0 75 | extraExposedTransformPaths: [] 76 | clipAnimations: [] 77 | isReadable: 1 78 | meshes: 79 | lODScreenPercentages: [] 80 | globalScale: 100 81 | meshCompression: 0 82 | addColliders: 0 83 | importBlendShapes: 1 84 | swapUVChannels: 0 85 | generateSecondaryUV: 0 86 | useFileUnits: 1 87 | optimizeMeshForGPU: 1 88 | keepQuads: 0 89 | weldVertices: 1 90 | secondaryUVAngleDistortion: 8 91 | secondaryUVAreaDistortion: 15.000001 92 | secondaryUVHardAngle: 88 93 | secondaryUVPackMargin: 4 94 | useFileScale: 1 95 | tangentSpace: 96 | normalSmoothAngle: 60 97 | normalImportMode: 0 98 | tangentImportMode: 3 99 | importAnimation: 1 100 | copyAvatar: 0 101 | humanDescription: 102 | human: [] 103 | skeleton: [] 104 | armTwist: 0.5 105 | foreArmTwist: 0.5 106 | upperLegTwist: 0.5 107 | legTwist: 0.5 108 | armStretch: 0.05 109 | legStretch: 0.05 110 | feetSpacing: 0 111 | rootMotionBoneName: 112 | hasTranslationDoF: 0 113 | lastHumanDescriptionAvatarSource: {instanceID: 0} 114 | animationType: 2 115 | humanoidOversampling: 1 116 | additionalBone: 0 117 | userData: 118 | assetBundleName: 119 | assetBundleVariant: 120 | -------------------------------------------------------------------------------- /Assets/Low_Poly_Sport_Car_ME_R4.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a46e3592973dc48e99bfbc24b611cabc 3 | folderAsset: yes 4 | timeCreated: 1463574684 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Low_Poly_Sport_Car_ME_R4/CC_ME_R4.FBX: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity-car-tutorials/SimpleRaycastVehicle-Unity/bc512747091fbbef100b2e7be3bce3ac1aec2cec/Assets/Low_Poly_Sport_Car_ME_R4/CC_ME_R4.FBX -------------------------------------------------------------------------------- /Assets/Low_Poly_Sport_Car_ME_R4/CC_ME_R4.FBX.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a74c4f07e37f8f04fa15f35de76ebaff 3 | ModelImporter: 4 | serializedVersion: 19 5 | fileIDToRecycleName: 6 | 100000: CC_ME_Body_R4 7 | 100002: //RootNode 8 | 100004: CC_ME_Wheel_BL 9 | 100006: CC_ME_Wheel_BR 10 | 100008: CC_ME_Wheel_FL 11 | 100010: CC_ME_Wheel_FR 12 | 400000: CC_ME_Body_R4 13 | 400002: //RootNode 14 | 400004: CC_ME_Wheel_BL 15 | 400006: CC_ME_Wheel_BR 16 | 400008: CC_ME_Wheel_FL 17 | 400010: CC_ME_Wheel_FR 18 | 2300000: CC_ME_Body_R4 19 | 2300002: CC_ME_Wheel_BL 20 | 2300004: CC_ME_Wheel_BR 21 | 2300006: CC_ME_Wheel_FL 22 | 2300008: CC_ME_Wheel_FR 23 | 3300000: CC_ME_Body_R4 24 | 3300002: CC_ME_Wheel_BL 25 | 3300004: CC_ME_Wheel_BR 26 | 3300006: CC_ME_Wheel_FL 27 | 3300008: CC_ME_Wheel_FR 28 | 4300000: CC_ME_Body_R4 29 | 4300002: CC_ME_Wheel_FR 30 | 4300004: CC_ME_Wheel_BR 31 | 4300006: CC_ME_Wheel_FL 32 | 4300008: CC_ME_Wheel_BL 33 | 9500000: //RootNode 34 | materials: 35 | importMaterials: 1 36 | materialName: 0 37 | materialSearch: 1 38 | animations: 39 | legacyGenerateAnimations: 4 40 | bakeSimulation: 0 41 | resampleRotations: 1 42 | optimizeGameObjects: 0 43 | motionNodeName: 44 | animationImportErrors: 45 | animationImportWarnings: 46 | animationRetargetingWarnings: 47 | animationDoRetargetingWarnings: 0 48 | animationCompression: 1 49 | animationRotationError: 0.5 50 | animationPositionError: 0.5 51 | animationScaleError: 0.5 52 | animationWrapMode: 0 53 | extraExposedTransformPaths: [] 54 | clipAnimations: [] 55 | isReadable: 1 56 | meshes: 57 | lODScreenPercentages: [] 58 | globalScale: 0.01 59 | meshCompression: 0 60 | addColliders: 0 61 | importBlendShapes: 1 62 | swapUVChannels: 0 63 | generateSecondaryUV: 0 64 | useFileUnits: 1 65 | optimizeMeshForGPU: 1 66 | keepQuads: 0 67 | weldVertices: 1 68 | secondaryUVAngleDistortion: 8 69 | secondaryUVAreaDistortion: 15.000001 70 | secondaryUVHardAngle: 88 71 | secondaryUVPackMargin: 4 72 | useFileScale: 0 73 | tangentSpace: 74 | normalSmoothAngle: 60 75 | normalImportMode: 0 76 | tangentImportMode: 4 77 | importAnimation: 1 78 | copyAvatar: 0 79 | humanDescription: 80 | human: [] 81 | skeleton: [] 82 | armTwist: 0.5 83 | foreArmTwist: 0.5 84 | upperLegTwist: 0.5 85 | legTwist: 0.5 86 | armStretch: 0.05 87 | legStretch: 0.05 88 | feetSpacing: 0 89 | rootMotionBoneName: 90 | hasTranslationDoF: 0 91 | lastHumanDescriptionAvatarSource: {instanceID: 0} 92 | animationType: 2 93 | humanoidOversampling: 1 94 | additionalBone: 0 95 | userData: 96 | assetBundleName: 97 | assetBundleVariant: 98 | -------------------------------------------------------------------------------- /Assets/Low_Poly_Sport_Car_ME_R4/Materials.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 16948874e5b0d46c89e5c059bca691e8 3 | folderAsset: yes 4 | timeCreated: 1463574684 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Low_Poly_Sport_Car_ME_R4/Materials/CC_ME_Body_R4.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity-car-tutorials/SimpleRaycastVehicle-Unity/bc512747091fbbef100b2e7be3bce3ac1aec2cec/Assets/Low_Poly_Sport_Car_ME_R4/Materials/CC_ME_Body_R4.mat -------------------------------------------------------------------------------- /Assets/Low_Poly_Sport_Car_ME_R4/Materials/CC_ME_Body_R4.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e98b8f85a22b836418b8eec498561962 3 | NativeFormatImporter: 4 | userData: 5 | assetBundleName: 6 | assetBundleVariant: 7 | -------------------------------------------------------------------------------- /Assets/Low_Poly_Sport_Car_ME_R4/Materials/CC_ME_Body_R4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity-car-tutorials/SimpleRaycastVehicle-Unity/bc512747091fbbef100b2e7be3bce3ac1aec2cec/Assets/Low_Poly_Sport_Car_ME_R4/Materials/CC_ME_Body_R4.png -------------------------------------------------------------------------------- /Assets/Low_Poly_Sport_Car_ME_R4/Materials/CC_ME_Body_R4.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 23d91df9eac3c8e4f959844815067ce8 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | serializedVersion: 2 6 | mipmaps: 7 | mipMapMode: 0 8 | enableMipMap: 1 9 | linearTexture: 0 10 | correctGamma: 0 11 | fadeOut: 0 12 | borderMipMap: 0 13 | mipMapFadeDistanceStart: 1 14 | mipMapFadeDistanceEnd: 3 15 | bumpmap: 16 | convertToNormalMap: 0 17 | externalNormalMap: 0 18 | heightScale: 0.25 19 | normalMapFilter: 0 20 | isReadable: 0 21 | grayScaleToAlpha: 0 22 | generateCubemap: 0 23 | cubemapConvolution: 0 24 | cubemapConvolutionSteps: 7 25 | cubemapConvolutionExponent: 1.5 26 | seamlessCubemap: 0 27 | textureFormat: -1 28 | maxTextureSize: 1024 29 | textureSettings: 30 | filterMode: 2 31 | aniso: 6 32 | mipBias: -1 33 | wrapMode: -1 34 | nPOTScale: 1 35 | lightmap: 0 36 | rGBM: 0 37 | compressionQuality: 50 38 | allowsAlphaSplitting: 0 39 | spriteMode: 0 40 | spriteExtrude: 1 41 | spriteMeshType: 1 42 | alignment: 0 43 | spritePivot: {x: 0.5, y: 0.5} 44 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 45 | spritePixelsToUnits: 100 46 | alphaIsTransparency: 0 47 | textureType: -1 48 | buildTargetSettings: [] 49 | spriteSheet: 50 | sprites: [] 51 | outline: [] 52 | spritePackingTag: 53 | userData: 54 | assetBundleName: 55 | assetBundleVariant: 56 | -------------------------------------------------------------------------------- /Assets/Low_Poly_Sport_Car_ME_R4/Materials/CC_ME_Wheels_R4.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity-car-tutorials/SimpleRaycastVehicle-Unity/bc512747091fbbef100b2e7be3bce3ac1aec2cec/Assets/Low_Poly_Sport_Car_ME_R4/Materials/CC_ME_Wheels_R4.mat -------------------------------------------------------------------------------- /Assets/Low_Poly_Sport_Car_ME_R4/Materials/CC_ME_Wheels_R4.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f0b593277981f9f45b9a9554f2dd280a 3 | NativeFormatImporter: 4 | userData: 5 | assetBundleName: 6 | assetBundleVariant: 7 | -------------------------------------------------------------------------------- /Assets/Low_Poly_Sport_Car_ME_R4/Materials/CC_ME_Wheels_R4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity-car-tutorials/SimpleRaycastVehicle-Unity/bc512747091fbbef100b2e7be3bce3ac1aec2cec/Assets/Low_Poly_Sport_Car_ME_R4/Materials/CC_ME_Wheels_R4.png -------------------------------------------------------------------------------- /Assets/Low_Poly_Sport_Car_ME_R4/Materials/CC_ME_Wheels_R4.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 77871bd6d9d8d57488452ca647ec1d4e 3 | TextureImporter: 4 | fileIDToRecycleName: {} 5 | serializedVersion: 2 6 | mipmaps: 7 | mipMapMode: 0 8 | enableMipMap: 1 9 | linearTexture: 0 10 | correctGamma: 0 11 | fadeOut: 0 12 | borderMipMap: 0 13 | mipMapFadeDistanceStart: 1 14 | mipMapFadeDistanceEnd: 3 15 | bumpmap: 16 | convertToNormalMap: 0 17 | externalNormalMap: 0 18 | heightScale: 0.25 19 | normalMapFilter: 0 20 | isReadable: 0 21 | grayScaleToAlpha: 0 22 | generateCubemap: 0 23 | cubemapConvolution: 0 24 | cubemapConvolutionSteps: 7 25 | cubemapConvolutionExponent: 1.5 26 | seamlessCubemap: 0 27 | textureFormat: -1 28 | maxTextureSize: 1024 29 | textureSettings: 30 | filterMode: 2 31 | aniso: 6 32 | mipBias: -1 33 | wrapMode: -1 34 | nPOTScale: 1 35 | lightmap: 0 36 | rGBM: 0 37 | compressionQuality: 50 38 | allowsAlphaSplitting: 0 39 | spriteMode: 0 40 | spriteExtrude: 1 41 | spriteMeshType: 1 42 | alignment: 0 43 | spritePivot: {x: 0.5, y: 0.5} 44 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 45 | spritePixelsToUnits: 100 46 | alphaIsTransparency: 0 47 | textureType: -1 48 | buildTargetSettings: [] 49 | spriteSheet: 50 | sprites: [] 51 | outline: [] 52 | spritePackingTag: 53 | userData: 54 | assetBundleName: 55 | assetBundleVariant: 56 | -------------------------------------------------------------------------------- /Assets/Materials.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a0027503d6df141e7ac193470b8907ff 3 | folderAsset: yes 4 | timeCreated: 1463670057 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Materials/Asphalt.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity-car-tutorials/SimpleRaycastVehicle-Unity/bc512747091fbbef100b2e7be3bce3ac1aec2cec/Assets/Materials/Asphalt.mat -------------------------------------------------------------------------------- /Assets/Materials/Asphalt.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2315b26ae973745d4ba1fbf53403db8a 3 | timeCreated: 1463670067 4 | licenseType: Free 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Prefabs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d8a128edd9a63471e97692586db3e1aa 3 | folderAsset: yes 4 | timeCreated: 1463779296 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Prefabs/Vehicle1.prefab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity-car-tutorials/SimpleRaycastVehicle-Unity/bc512747091fbbef100b2e7be3bce3ac1aec2cec/Assets/Prefabs/Vehicle1.prefab -------------------------------------------------------------------------------- /Assets/Prefabs/Vehicle1.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6715386a195e94c55ab225fcea884d62 3 | timeCreated: 1463779314 4 | licenseType: Free 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Prefabs/Vehicle2.prefab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity-car-tutorials/SimpleRaycastVehicle-Unity/bc512747091fbbef100b2e7be3bce3ac1aec2cec/Assets/Prefabs/Vehicle2.prefab -------------------------------------------------------------------------------- /Assets/Prefabs/Vehicle2.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7a264635e1858487bbb726e39a115ed2 3 | timeCreated: 1463779250 4 | licenseType: Free 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Scenes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fda04f548625b48e1b99480504adc250 3 | folderAsset: yes 4 | timeCreated: 1463574719 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Scenes/Example1.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity-car-tutorials/SimpleRaycastVehicle-Unity/bc512747091fbbef100b2e7be3bce3ac1aec2cec/Assets/Scenes/Example1.unity -------------------------------------------------------------------------------- /Assets/Scenes/Example1.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b4a3eafeaa89741069b5d3a43c71d651 3 | timeCreated: 1463574732 4 | licenseType: Free 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Scenes/Example2.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity-car-tutorials/SimpleRaycastVehicle-Unity/bc512747091fbbef100b2e7be3bce3ac1aec2cec/Assets/Scenes/Example2.unity -------------------------------------------------------------------------------- /Assets/Scenes/Example2.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5ccf3868e849346f7bd3d6d8b1ac6394 3 | timeCreated: 1463779187 4 | licenseType: Free 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4381ce5302e514b8999c4cca194258ff 3 | folderAsset: yes 4 | timeCreated: 1463574151 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Scripts/Controller.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | [RequireComponent(typeof(Rigidbody))] 5 | public class Controller : MonoBehaviour { 6 | 7 | private Rigidbody rb; 8 | public Transform FL, FR, BL, BR; 9 | public float torque = 100; 10 | public float maxAngle = 30; 11 | 12 | // Use this for initialization 13 | void Start () { 14 | rb = GetComponent (); 15 | rb.centerOfMass = new Vector3 (0, -.5f, 0); 16 | } 17 | 18 | // Update is called once per frame 19 | void FixedUpdate () { 20 | 21 | float forward = Input.GetAxis ("Vertical"); 22 | float steer = Input.GetAxis ("Horizontal"); 23 | 24 | Vector3 ff = (Vector3.forward * torque * forward); 25 | //Vector3 ss = (Vector3.up * torque * 100 * steer); 26 | 27 | rb.AddRelativeForce (ff); 28 | //rb.AddRelativeTorque (ss); 29 | if (FL & FR) 30 | { 31 | FR.localRotation = Quaternion.AngleAxis (steer * maxAngle, Vector3.up); 32 | FL.localRotation = Quaternion.AngleAxis (steer * maxAngle, Vector3.up); 33 | 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Assets/Scripts/Controller.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 77d79b9a6a0c445d3a43050b4dd74ccf 3 | timeCreated: 1463581378 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Scripts/FollowTarget.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace UnityStandardAssets.Utility 5 | { 6 | 7 | public class FollowTarget : MonoBehaviour 8 | { 9 | /* 10 | This camera smoothes out rotation around the y-axis and height. 11 | Horizontal Distance to the target is always fixed. 12 | 13 | There are many different ways to smooth the rotation but doing it this way gives you a lot of control over how the camera behaves. 14 | 15 | For every of those smoothed values we calculate the wanted value and the current value. 16 | Then we smooth it using the Lerp function. 17 | Then we apply the smoothed values to the transform's position. 18 | */ 19 | 20 | // The target we are following 21 | public Transform target; 22 | // The distance in the x-z plane to the target 23 | public float distance = 10.0f; 24 | // the height we want the camera to be above the target 25 | public float height = 5.0f; 26 | // How much we 27 | public float heightDamping = 2.0f; 28 | public float rotationDamping = 3.0f; 29 | 30 | void LateUpdate (){ 31 | // Early out if we don't have a target 32 | if (!target) 33 | return; 34 | 35 | // Calculate the current rotation angles 36 | float wantedRotationAngle = target.eulerAngles.y; 37 | float wantedHeight = target.position.y + height; 38 | 39 | float currentRotationAngle = transform.eulerAngles.y; 40 | float currentHeight = transform.position.y; 41 | 42 | // Damp the rotation around the y-axis 43 | currentRotationAngle = Mathf.LerpAngle (currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime); 44 | 45 | // Damp the height 46 | currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime); 47 | 48 | // Convert the angle into a rotation 49 | Quaternion currentRotation= Quaternion.Euler (0, currentRotationAngle, 0); 50 | 51 | // Set the position of the camera on the x-z plane to: 52 | // distance meters behind the target 53 | transform.position = target.position; 54 | transform.position -= currentRotation * Vector3.forward * distance; 55 | 56 | // Set the height of the camera 57 | transform.position = new Vector3(transform.position.x, currentHeight, transform.position.z); 58 | 59 | // Always look at the target 60 | transform.LookAt (target); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Assets/Scripts/FollowTarget.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 484bc8d372df847d4a73581a466a7de3 3 | timeCreated: 1463662144 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Scripts/PlayerCar.cs: -------------------------------------------------------------------------------- 1 |  2 | // Converted from UnityScript to C# at http://www.M2H.nl/files/js_to_c.php - by Mike Hergaarden 3 | // Do test the code! You usually need to change a few small bits. 4 | 5 | using UnityEngine; 6 | using System.Collections; 7 | 8 | public class PlayerCar : MonoBehaviour { 9 | 10 | // car physics calculations/input stuff 11 | private Vector3 accel; 12 | public float throttle; 13 | private float deadZone = .001f; 14 | private Vector3 myRight; 15 | private Vector3 velo; 16 | private Vector3 flatVelo; 17 | private Vector3 relativeVelocity; 18 | private Vector3 dir; 19 | private Vector3 flatDir; 20 | private Vector3 carUp; 21 | private Transform carTransform; 22 | private Rigidbody carRigidbody; 23 | private Vector3 engineForce; 24 | 25 | private Vector3 turnVec; 26 | private Vector3 imp; 27 | private float rev; 28 | private float actualTurn; 29 | private float carMass; 30 | private Transform[] wheelTransform = new Transform[4]; //these are the transforms for our 4 wheels 31 | public float actualGrip; 32 | public float horizontal; //horizontal input control, either mobile control or keyboard 33 | private float maxSpeedToTurn = .2f; //keeps car from turning until it's reached this value 34 | 35 | // the physical transforms for the car's wheels 36 | public Transform frontLeftWheel; 37 | public Transform frontRightWheel; 38 | public Transform rearLeftWheel; 39 | public Transform rearRightWheel; 40 | 41 | public RaycastWheelSimple frontLeftRayCast; 42 | public RaycastWheelSimple frontRightRayCast; 43 | 44 | //these transform parents will allow wheels to turn for steering/separates steering turn from acceleration turning 45 | public Transform LFWheelTransform; 46 | public Transform RFWheelTransform; 47 | 48 | // car physics adjustments 49 | public float power = 300; 50 | public float maxSpeed = 50; 51 | public float carGrip = 70; 52 | public float turnSpeed = 3.0f; //keep this value somewhere between 2.5f and 6.0f 53 | 54 | private float slideSpeed; 55 | public float mySpeed; 56 | 57 | private Vector3 carRight; 58 | private Vector3 carFwd; 59 | private Vector3 tempVEC; 60 | 61 | private float xr = 0; 62 | 63 | private AudioSource audio; 64 | 65 | void Start (){ 66 | Initialize(); 67 | } 68 | 69 | void Initialize (){ 70 | // Cache a reference to our car's transform 71 | carTransform = transform; 72 | // cache the rigidbody for our car 73 | carRigidbody = GetComponent(); 74 | // cache our vector up direction 75 | carUp = carTransform.up; 76 | // cache the mass of our vehicle 77 | carMass = GetComponent().mass; 78 | // cache the Forward World Vector for our car 79 | carFwd = Vector3.forward; 80 | // cache the World Right Vector for our car 81 | carRight = Vector3.right; 82 | // call to set up our wheels array 83 | setUpWheels(); 84 | // we set a COG here and lower the center of mass to a 85 | //negative value in Y axis to prevent car from flipping over 86 | carRigidbody.centerOfMass = new Vector3(0f,-1.7f,.35f); 87 | audio = GetComponent (); 88 | frontLeftRayCast = frontLeftWheel.GetComponentInParent (); 89 | frontRightRayCast = frontRightWheel.GetComponentInParent (); 90 | 91 | } 92 | 93 | void Update (){ 94 | // call the function to start processing all vehicle physics 95 | carPhysicsUpdate(); 96 | 97 | 98 | //call the function to see what input we are using and apply it 99 | checkInput(); 100 | 101 | 102 | 103 | } 104 | 105 | void LateUpdate (){ 106 | // this function makes the visual 3d wheels rotate and turn 107 | rotateVisualWheels(); 108 | 109 | //this is where we send to a function to do engine sounds 110 | engineSound(); 111 | } 112 | 113 | void setUpWheels (){ 114 | if((null == frontLeftWheel || null == frontRightWheel || null == rearLeftWheel || null == rearRightWheel )) 115 | { 116 | Debug.LogError("One or more of the wheel transforms have not been plugged in on the car"); 117 | Debug.Break(); 118 | } 119 | else 120 | { 121 | //set up the car's wheel transforms 122 | wheelTransform[0] = frontLeftWheel; 123 | wheelTransform[1] = rearLeftWheel; 124 | wheelTransform[2] = frontRightWheel; 125 | wheelTransform[3] = rearRightWheel; 126 | } 127 | } 128 | 129 | private Vector3 rotationAmount; 130 | 131 | void rotateVisualWheels (){ 132 | // front wheels visual rotation while steering the car 133 | 134 | xr += (float)(relativeVelocity.z * 1.6 * Time.deltaTime * Mathf.Rad2Deg); 135 | 136 | for (int i = 0; i < 4; i++) { 137 | float yr = 0; 138 | 139 | if (wheelTransform [i] == RFWheelTransform || wheelTransform [i] == LFWheelTransform) 140 | yr = horizontal * 30; 141 | 142 | wheelTransform[i].localRotation = Quaternion.Euler(new Vector3 (xr, yr, 0)); 143 | } 144 | /* 145 | Vector3 rotationAmount = carRight *(float)(relativeVelocity.z * 1.6 * Time.deltaTime * Mathf.Rad2Deg); 146 | 147 | wheelTransform[0].Rotate(rotationAmount); 148 | wheelTransform[1].Rotate(rotationAmount); 149 | wheelTransform[2].Rotate(rotationAmount); 150 | wheelTransform[3].Rotate(rotationAmount); 151 | */ 152 | 153 | if (xr >= 360f) 154 | xr -= 360f; 155 | 156 | } 157 | 158 | private float deviceAccelerometerSensitivity = 2; //how sensitive our mobile accelerometer will be 159 | 160 | void checkInput (){ 161 | 162 | 163 | //Use the Keyboard for all car input 164 | horizontal = Input.GetAxis("Horizontal"); 165 | throttle = Input.GetAxis("Vertical"); 166 | 167 | } 168 | 169 | void carPhysicsUpdate (){ 170 | //grab all the physics info we need to calc everything 171 | myRight = carTransform.right; 172 | 173 | // find our velocity 174 | Vector3 velo = carRigidbody.velocity; 175 | 176 | Vector3 tempVEC = new Vector3(velo.x,0,velo.z); 177 | 178 | // figure out our velocity without y movement - our flat velocity 179 | flatVelo = tempVEC; 180 | 181 | // find out which direction we are moving in 182 | dir = transform.TransformDirection(carFwd); 183 | 184 | tempVEC = new Vector3(dir.x,0,dir.z); 185 | 186 | // calculate our direction, removing y movement - our flat direction 187 | flatDir = Vector3.Normalize(tempVEC); 188 | 189 | // calculate relative velocity 190 | relativeVelocity = carTransform.InverseTransformDirection(flatVelo); 191 | 192 | // calculate how much we are sliding (find out movement along our x axis) 193 | slideSpeed = Vector3.Dot(myRight,flatVelo); 194 | 195 | // calculate current speed (the magnitude of the flat velocity) 196 | mySpeed = flatVelo.magnitude; 197 | 198 | // check to see if we are moving in reverse 199 | rev = Mathf.Sign(Vector3.Dot(flatVelo,flatDir)); 200 | 201 | // calculate engine force with our flat direction vector and acceleration 202 | engineForce = ( flatDir * ( power * throttle ) * carMass); 203 | 204 | // do turning 205 | actualTurn = horizontal; 206 | 207 | // if we're in reverse, we reverse the turning direction too 208 | if(rev < 0.1f) 209 | { 210 | actualTurn =- actualTurn; 211 | } 212 | 213 | // calculate torque for applying to our rigidbody 214 | turnVec =((( carUp * turnSpeed ) * actualTurn ) * carMass )* 800; 215 | 216 | // calculate impulses to simulate grip by taking our right vector, reversing the slidespeed and 217 | // multiplying that by our mass, to give us a completely 'corrected' force that would completely 218 | // stop sliding. we then multiply that by our grip amount (which is, technically, a slide amount) which 219 | // reduces the corrected force so that it only helps to reduce sliding rather than completely 220 | // stop it 221 | 222 | actualGrip = Mathf.Lerp(100, carGrip, mySpeed * 0.02f); 223 | imp = myRight * ( -slideSpeed * carMass * actualGrip); 224 | 225 | } 226 | 227 | void slowVelocity (){ 228 | carRigidbody.AddForce(-flatVelo * 0.8f); 229 | } 230 | 231 | //this controls the sound of the engine audio by adjusting the pitch of our sound file 232 | void engineSound (){ 233 | 234 | if (audio) 235 | { 236 | audio.pitch = 0.30f + mySpeed * 0.025f; 237 | 238 | if (mySpeed > 30) 239 | { 240 | audio.pitch = 0.25f + mySpeed * 0.015f; 241 | } 242 | if (mySpeed > 40) 243 | { 244 | audio.pitch = 0.20f + mySpeed * 0.013f; 245 | } 246 | if (mySpeed > 49) 247 | { 248 | audio.pitch = 0.15f + mySpeed * 0.011f; 249 | } 250 | //ensures we dont exceed to crazy of a pitch by resetting it back to default 2 251 | if (audio.pitch > 2.0f) { 252 | audio.pitch = 2.0f; 253 | } 254 | } 255 | } 256 | 257 | void FixedUpdate (){ 258 | if(mySpeed < maxSpeed) 259 | { 260 | // apply the engine force to the rigidbody 261 | carRigidbody.AddForce( engineForce * Time.deltaTime ); 262 | } 263 | //if we're going to slow to allow kart to rotate around 264 | if(mySpeed > maxSpeedToTurn) 265 | { 266 | // apply torque to our rigidbody 267 | carRigidbody.AddTorque ( turnVec * Time.deltaTime ); 268 | } 269 | else if(mySpeed < maxSpeedToTurn) 270 | { 271 | return; 272 | } 273 | // apply forces to our rigidbody for grip 274 | carRigidbody.AddForce( imp * Time.deltaTime ); 275 | } 276 | } -------------------------------------------------------------------------------- /Assets/Scripts/PlayerCar.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4ba2dbe6ed02a44ef92e056c333433e5 3 | timeCreated: 1463652917 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Scripts/RaycastWheel.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | // Do test the code! You usually need to change a few small bits. 5 | 6 | [RequireComponent(typeof(Rigidbody))] 7 | public class RaycastWheel : MonoBehaviour { 8 | 9 | // More advanced Vehicle Raycast wheel 10 | 11 | public Transform graphic; 12 | 13 | public float mass = 1.00f; 14 | public float wheelRadius = 0.5f; 15 | public float suspensionRange = 0.10f; 16 | public float suspensionForce = 0.00f; 17 | public float suspensionDamp = 0.00f; 18 | public float compressionFrictionFactor = 0.00f; 19 | 20 | public float sidewaysFriction = 0.00f; 21 | public float sidewaysDamp = 0.00f; 22 | public float sidewaysSlipVelocity = 0.00f; 23 | public float sidewaysSlipForce = 0.00f; 24 | public float sidewaysSlipFriction = 0.00f; 25 | public float sidewaysStiffnessFactor = 0.00f; 26 | 27 | public float forwardFriction = 0.00f; 28 | public float forwardSlipVelocity = 0.00f; 29 | public float forwardSlipForce = 0.00f; 30 | public float forwardSlipFriction = 0.00f; 31 | public float forwardStiffnessFactor = 0.00f; 32 | 33 | public float frictionSmoothing = 1.00f; 34 | 35 | public float usedSideFriction = 0.00f; 36 | public float usedForwardFriction = 0.00f; 37 | public float sideSlip = 0.00f; 38 | public float forwardSlip = 0.00f; 39 | 40 | public bool driven = false; 41 | public bool brake = false; 42 | public bool skidbrake = false; 43 | 44 | public float speed = 0.00f; 45 | 46 | private RaycastHit hit; 47 | 48 | private Rigidbody parent; 49 | 50 | private float wheelCircumference = 0.00f; 51 | 52 | private bool grounded = false; 53 | 54 | public bool IsGrounded 55 | { 56 | get 57 | { 58 | return grounded; 59 | } 60 | } 61 | 62 | void Start () 63 | { 64 | wheelCircumference = wheelRadius * Mathf.PI * 2; 65 | parent = transform.root.GetComponent(); 66 | } 67 | 68 | void FixedUpdate () 69 | { 70 | // the object this script is attached to does not move. This ray is like imagining 71 | // that the shock is compressed as much as possible, and then extends out as far as it can before it hits the ground. 72 | // If it doesn't, then the wheel is fully extended. 73 | 74 | Vector3 down = transform.TransformDirection(Vector3.down); 75 | 76 | // if raycast from position downwards with range suspensionrange + wheelRadius 77 | // and hit.collider != the parent (car) 78 | 79 | // calculate the force of the shock as it pushes on the car and the earth due to compression. 80 | // Since the earth does not move, this is an upward force on the car only 81 | 82 | if(Physics.Raycast (transform.position, down, out hit, suspensionRange + wheelRadius) && hit.collider.transform.root != transform.root) 83 | { 84 | // how fast is the wheel moving relative to the ground, without taking the wheel's rotation into account 85 | Vector3 velocityAtTouch = parent.GetPointVelocity(hit.point); 86 | 87 | // calculate spring compression 88 | // difference in positions divided by total suspension range 89 | float compression = hit.distance / (suspensionRange + wheelRadius); 90 | compression = -compression + 1; 91 | 92 | // final force 93 | Vector3 force = -down * compression * suspensionForce; 94 | 95 | 96 | // velocity at point of contact transformed into local space 97 | Vector3 t = transform.InverseTransformDirection(velocityAtTouch); 98 | 99 | // local x and z directions = 0 100 | // Here we set t equal to the speed at which the shock is contracting / expanding 101 | t.z = 0; 102 | t.x = 0; 103 | 104 | // back to world space * -damping 105 | // this force simulates the force exerted by the friction in the suspension. 106 | Vector3 shockDrag = transform.TransformDirection(t) * -suspensionDamp; 107 | 108 | // forwardDifference = local speed along the z axis 109 | // the difference between the speed of the ground and the wheel taking rotation + the car's velocity into account. 110 | // (in local space, that means, relative to the wheel. So if you were standing on the wheel surface, 111 | // how fast would you percieve the ground moving? Either squashing you every time the wheel goes around 112 | // (not skidding, absolute value close to zero) or scrapping you to bits (skidding, large absolute value)) 113 | 114 | float forwardDifference = transform.InverseTransformDirection(velocityAtTouch).z - speed; 115 | 116 | // newForwardFriction = interpolated between forwardFriction (constant) and 117 | // forwardSlipFriction. Interpolation is forwardSlip squared. 118 | // so if forwardSlip = 1, newForwardFriction = forwardSlipFriction 119 | 120 | 121 | //Ok, this next part is not related to real physics an any way whatsoever. Ummm... Basically the friction that the wheel has with 122 | // the ground changes (using a lerp function over time) depending on the current friction force. 123 | // I guess this simulates how once a car starts skidding, the friction goes down so it skids more. 124 | // __________________z-friction__________________ 125 | // move the current working friction value toward the minimum about porportional to the "skidding-ness" squared 126 | 127 | float newForwardFriction = Mathf.Lerp(forwardFriction, forwardSlipFriction, forwardSlip * forwardSlip); 128 | 129 | // increase the current working friction value depending on how hard the shock is pressing the wheel against the ground 130 | newForwardFriction = Mathf.Lerp(newForwardFriction, newForwardFriction * compression * 1, compressionFrictionFactor); 131 | 132 | if(frictionSmoothing > 0) 133 | usedForwardFriction = Mathf.Lerp(usedForwardFriction, newForwardFriction, Time.fixedDeltaTime / frictionSmoothing); 134 | else 135 | usedForwardFriction = newForwardFriction; 136 | 137 | // calculate one component of the friction force: the difference between the wheel surface velocity and ground surface 138 | // velocity times friction (not based on real physics AFAIK) 139 | Vector3 forwardForce = transform.TransformDirection(new Vector3(0, 0, -forwardDifference)) * usedForwardFriction; 140 | 141 | // calculate how much we be slippin (if the force is high, the tire will give and slip on the road) 142 | forwardSlip = Mathf.Lerp(forwardForce.magnitude / forwardSlipForce, forwardDifference / forwardSlipVelocity, forwardStiffnessFactor); 143 | 144 | float sidewaysDifference = transform.InverseTransformDirection(velocityAtTouch).x; 145 | float newSideFriction = Mathf.Lerp(sidewaysFriction, sidewaysSlipFriction, sideSlip * sideSlip); 146 | newSideFriction = Mathf.Lerp(newSideFriction, newSideFriction * compression * 1, compressionFrictionFactor); 147 | 148 | if(frictionSmoothing > 0) 149 | usedSideFriction = Mathf.Lerp(usedSideFriction, newSideFriction, Time.fixedDeltaTime / frictionSmoothing); 150 | else 151 | usedSideFriction = newSideFriction; 152 | 153 | // ____________________________________ 154 | // this is much the same as the block above, but for the x-axis 155 | // __________________x-friction__________________ 156 | 157 | Vector3 sideForce = transform.TransformDirection(new Vector3(-sidewaysDifference, 0, 0)) * usedSideFriction; 158 | sideSlip = Mathf.Lerp(sideForce.magnitude / sidewaysSlipForce, sidewaysDifference / sidewaysSlipVelocity, sidewaysStiffnessFactor); 159 | 160 | // this thing is totally made up. It's as if god's hand nudges the car back on course whenever it is moving sideways, 161 | // by a factor of sidewaysDamp 162 | t = transform.InverseTransformDirection(velocityAtTouch); 163 | t.z = 0; 164 | t.y = 0; 165 | 166 | Vector3 sideDrag = transform.TransformDirection(t) * -sidewaysDamp; 167 | 168 | // By the some of all you combined, I become CAPTAIN FORCE 169 | parent.AddForceAtPosition(force + shockDrag - forwardForce + sideForce + sideDrag, transform.position); 170 | 171 | 172 | // for every action there is an opposite reaction: the wheel adds a force on the ground, but the ground does not move, 173 | // so that force is added to the car instead in the opposite direction (this lets the engine propel the thing forward). 174 | // But!!! we also have to add a force on the engine, because otherwise we'd be adding force from nothing. 175 | // The opposite reaction is this force on the motor. The motor is not a rigidbody, it is a made up thing in the Car.js script 176 | if(driven) 177 | { 178 | //car.AddForceOnMotor (forwardDifference * usedForwardFriction * Time.fixedDeltaTime); 179 | } 180 | else 181 | speed += forwardDifference; 182 | 183 | graphic.position = transform.position + (down * (hit.distance - wheelRadius)); 184 | } 185 | else 186 | { 187 | graphic.position = transform.position + (down * suspensionRange); 188 | } 189 | 190 | speed = parent.velocity.magnitude; 191 | 192 | graphic.transform.Rotate(360 * (speed / wheelCircumference) * Time.fixedDeltaTime, 0, 0); 193 | } 194 | 195 | void OnDrawGizmosSelected () 196 | { 197 | Gizmos.color = new Color(0,1,0,1); 198 | Vector3 direction = transform.TransformDirection (-Vector3.up) * (this.wheelRadius); 199 | Gizmos.DrawRay(transform.position,direction); 200 | 201 | Gizmos.color = new Color(0,0,1,1); 202 | direction = transform.TransformDirection (-Vector3.up) * (this.suspensionRange); 203 | Gizmos.DrawRay(new Vector3(transform.position.x,transform.position.y - wheelRadius,transform.position.z),direction); 204 | } 205 | } -------------------------------------------------------------------------------- /Assets/Scripts/RaycastWheel.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c2e2f226450154d0d8e0f941a89d6975 3 | timeCreated: 1463585033 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Scripts/RaycastWheelSimple.cs: -------------------------------------------------------------------------------- 1 | // Converted from UnityScript to C# at http://www.M2H.nl/files/js_to_c.php - by Mike Hergaarden 2 | // Do test the code! You usually need to change a few small bits. 3 | 4 | using UnityEngine; 5 | using System.Collections; 6 | 7 | public class RaycastWheelSimple : MonoBehaviour { 8 | 9 | // Simple Vehicle Raycast wheel 10 | 11 | public Transform graphic; 12 | 13 | public float mass = 1.0f; 14 | public float radius = 1.0f; 15 | public float maxSuspension = 0.2f; 16 | public float spring = 100.0f; 17 | public float damper = 0.0f; 18 | 19 | public float wheelAngle = 0f; 20 | 21 | private float circumference; 22 | 23 | private float contactPatchArea; 24 | private Rigidbody parent; 25 | private bool grounded = false; 26 | 27 | public bool IsGrounded 28 | { 29 | get 30 | { 31 | return grounded; 32 | } 33 | } 34 | 35 | void Awake () 36 | { 37 | circumference = (radius * 2) * Mathf.PI; 38 | parent = transform.root.GetComponent(); 39 | } 40 | 41 | void FixedUpdate () 42 | { 43 | GetGround(); 44 | } 45 | 46 | void GetGround (){ 47 | grounded = false; 48 | Vector3 downwards = transform.TransformDirection (-Vector3.up); 49 | RaycastHit hit; 50 | 51 | // down = local downwards direction 52 | Vector3 down = transform.TransformDirection(Vector3.down); 53 | 54 | if (Physics.Raycast(transform.position, downwards, out hit, radius + maxSuspension)) { 55 | 56 | grounded = true; 57 | // the velocity at point of contact 58 | Vector3 velocityAtTouch = parent.GetPointVelocity(hit.point); 59 | 60 | // calculate spring compression 61 | // difference in positions divided by total suspension range 62 | float compression = hit.distance / (maxSuspension + radius); 63 | compression = -compression + 1; 64 | 65 | // final force 66 | Vector3 force = -downwards * compression * spring; 67 | // velocity at point of contact transformed into local space 68 | 69 | Vector3 t = transform.InverseTransformDirection(velocityAtTouch); 70 | 71 | // local x and z directions = 0 72 | t.z = t.x = 0; 73 | 74 | // back to world space * -damping 75 | Vector3 damping = transform.TransformDirection(t) * -damper; 76 | Vector3 finalForce = force + damping; 77 | 78 | // VERY simple turning - force rigidbody in direction of wheel 79 | t = parent.transform.InverseTransformDirection(velocityAtTouch); 80 | t.y = 0; 81 | t.z = 0; 82 | 83 | t = transform.TransformDirection(t); 84 | 85 | parent.AddForceAtPosition(finalForce + (t), hit.point); 86 | 87 | if (graphic) graphic.position = transform.position + (down * (hit.distance - radius)); 88 | 89 | } 90 | else 91 | { 92 | if (graphic) graphic.position = transform.position + (down * maxSuspension); 93 | } 94 | 95 | float speed = parent.velocity.magnitude; 96 | 97 | if (graphic) 98 | { 99 | //graphic.transform.localEulerAngles = new Vector3 (graphic.transform.localEulerAngles.x, wheelAngle, graphic.transform.localEulerAngles.z); 100 | //graphic.transform.Rotate (360 * (speed / circumference) * Time.fixedDeltaTime, 0, 0); 101 | } 102 | } 103 | 104 | void OnDrawGizmosSelected () 105 | { 106 | Gizmos.color = new Color(0,1,0,1); 107 | Vector3 direction = transform.TransformDirection (-Vector3.up) * (this.radius); 108 | Gizmos.DrawRay(transform.position,direction); 109 | 110 | Gizmos.color = new Color(0,0,1,1); 111 | direction = transform.TransformDirection (-Vector3.up) * (this.maxSuspension); 112 | Gizmos.DrawRay(new Vector3(transform.position.x,transform.position.y - radius,transform.position.z),direction); 113 | } 114 | } -------------------------------------------------------------------------------- /Assets/Scripts/RaycastWheelSimple.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4a2473d3ddafe4f0499d993e3e0be0a7 3 | timeCreated: 1463574160 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Textures.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6e715e49f8e9f42f0aa1068ed0bb45c8 3 | folderAsset: yes 4 | timeCreated: 1463670038 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Textures/asphalt.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity-car-tutorials/SimpleRaycastVehicle-Unity/bc512747091fbbef100b2e7be3bce3ac1aec2cec/Assets/Textures/asphalt.jpg -------------------------------------------------------------------------------- /Assets/Textures/asphalt.jpg.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e92267be18be34752b9ee534e3ea3833 3 | timeCreated: 1463670042 4 | licenseType: Free 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 2 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 1 11 | linearTexture: 0 12 | correctGamma: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 0 25 | cubemapConvolution: 0 26 | cubemapConvolutionSteps: 7 27 | cubemapConvolutionExponent: 1.5 28 | seamlessCubemap: 0 29 | textureFormat: -1 30 | maxTextureSize: 2048 31 | textureSettings: 32 | filterMode: 2 33 | aniso: 16 34 | mipBias: -1 35 | wrapMode: 0 36 | nPOTScale: 1 37 | lightmap: 0 38 | rGBM: 0 39 | compressionQuality: 50 40 | allowsAlphaSplitting: 0 41 | spriteMode: 0 42 | spriteExtrude: 1 43 | spriteMeshType: 1 44 | alignment: 0 45 | spritePivot: {x: 0.5, y: 0.5} 46 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 47 | spritePixelsToUnits: 100 48 | alphaIsTransparency: 0 49 | textureType: 0 50 | buildTargetSettings: [] 51 | spriteSheet: 52 | sprites: [] 53 | outline: [] 54 | spritePackingTag: 55 | userData: 56 | assetBundleName: 57 | assetBundleVariant: 58 | -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity-car-tutorials/SimpleRaycastVehicle-Unity/bc512747091fbbef100b2e7be3bce3ac1aec2cec/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity-car-tutorials/SimpleRaycastVehicle-Unity/bc512747091fbbef100b2e7be3bce3ac1aec2cec/ProjectSettings/ClusterInputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity-car-tutorials/SimpleRaycastVehicle-Unity/bc512747091fbbef100b2e7be3bce3ac1aec2cec/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity-car-tutorials/SimpleRaycastVehicle-Unity/bc512747091fbbef100b2e7be3bce3ac1aec2cec/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity-car-tutorials/SimpleRaycastVehicle-Unity/bc512747091fbbef100b2e7be3bce3ac1aec2cec/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity-car-tutorials/SimpleRaycastVehicle-Unity/bc512747091fbbef100b2e7be3bce3ac1aec2cec/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity-car-tutorials/SimpleRaycastVehicle-Unity/bc512747091fbbef100b2e7be3bce3ac1aec2cec/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity-car-tutorials/SimpleRaycastVehicle-Unity/bc512747091fbbef100b2e7be3bce3ac1aec2cec/ProjectSettings/NavMeshAreas.asset -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity-car-tutorials/SimpleRaycastVehicle-Unity/bc512747091fbbef100b2e7be3bce3ac1aec2cec/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity-car-tutorials/SimpleRaycastVehicle-Unity/bc512747091fbbef100b2e7be3bce3ac1aec2cec/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity-car-tutorials/SimpleRaycastVehicle-Unity/bc512747091fbbef100b2e7be3bce3ac1aec2cec/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 5.3.4f1 2 | m_StandardAssetsVersion: 0 3 | -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity-car-tutorials/SimpleRaycastVehicle-Unity/bc512747091fbbef100b2e7be3bce3ac1aec2cec/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity-car-tutorials/SimpleRaycastVehicle-Unity/bc512747091fbbef100b2e7be3bce3ac1aec2cec/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity-car-tutorials/SimpleRaycastVehicle-Unity/bc512747091fbbef100b2e7be3bce3ac1aec2cec/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /ProjectSettings/UnityAdsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity-car-tutorials/SimpleRaycastVehicle-Unity/bc512747091fbbef100b2e7be3bce3ac1aec2cec/ProjectSettings/UnityAdsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity-car-tutorials/SimpleRaycastVehicle-Unity/bc512747091fbbef100b2e7be3bce3ac1aec2cec/ProjectSettings/UnityConnectSettings.asset -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SimpleRaycastVehicle-Unity 2 | 3 | This Unity 5 project contains alternative raycast vehicle examples that were converted from Unityscript examples to C#. These examples are better suited to arcade style and mario kart style games, as well as mobile games with dozens of vehicles. 4 | --------------------------------------------------------------------------------