Система, позволяющая изменять террайн в реальном времени, имитировать бомбежку, стрельбу. Изменяет в определенной точке мешь террайна и текстуру. Примечания: высота террайна должна быть больше ноля, в демонстрации указана высота 3. Требования: 2.6.1, класс Detonator Framework.
Колеса и будут висеть, они не риджитБоди, у тебя физика висит не на колесах и не с колеей коллизит. А что, ты симулятор делаешь или игру? X.cor.R (Prologue)
я что то ничего непонял про риджитбоди на колёсах, если риджит боди подкинуть к колёсам они проваливаются
Тут всю конструкцию придеться менять. Подробнее не могу я не занимался гонками. Просто даю общие наводки, а подробнее сами. Возьми обыкновенный примитив, прицепи ему риджитБоди и посмотри с какими колайдерами он не провалиться. Выбирай используй. Как вариант можно тут использовать и характер контроллер. X.cor.R (Prologue)
Ребят,почему если я пытаюсь сделать деформация ландшафта,то иеняется только текстура? В стандартной сцене всё робит,ланд мнётся,а если пытаюсь сделать сам,то только текстура,ландшафт не меняется? Никаких тегов слоёв и прочей муйни там нет! Уже ОЧЕНЬ долго пытаюсь сделать,но не получается! Где и что я упустил? Неплохо знаю JavaScript(Unity3D API) =)
1.Создаю Terrain 2.Назначаю ему скрипт TerrainDeformer,там циферка 1. 3.Добавляю террайну вторую текстуру "dirt" 4.Добавляю стандартный префаб Shell 5.Запускаю...И он падает,текстура "взрыва" так сказать,появляется,но ландшафт не мнётся. В стандартной демке всё ок. Неплохо знаю JavaScript(Unity3D API) =)
мне кажется из пака все ровно можно достать все что нужно, но придется покапатся ну вот ошибки:
NullReferenceException: A null value was found where an object instance was required. UnityEngine.TerrainData.SetHeights (Int32 xBase, Int32 yBase, System.Single[,] heights) (at C:/BuildAgent/work/812c4f5049264fad/Runtime/ExportGenerated/Editor/Terrains.cs:242) TerrainDeformer.OnApplicationQuit () (at Assets/GameAssets/Scripts/TerrainDeformer.cs:65)
Код
// TerrainDeformer - Demonstrating a method modifying terrain in real-time. Changing height and texture // // released under MIT License // http://www.opensource.org/licenses/mit-license.php // //@author Devin Reimer //@website http://blog.almostlogical.com //Copyright (c) 2010 Devin Reimer /* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ using UnityEngine; using System.Collections;
public class TerrainDeformer : MonoBehaviour { public int terrainDeformationTextureNum = 1; private Terrain terr; // terrain to modify protected int hmWidth; // heightmap width protected int hmHeight; // heightmap height protected int alphaMapWidth; protected int alphaMapHeight; protected int numOfAlphaLayers; protected const float DEPTH_METER_CONVERT=0.05f; protected const float TEXTURE_SIZE_MULTIPLIER = 1.25f; private float[,] heightMapBackup; private float[, ,] alphaMapBackup;
//this has to be done because terrains for some reason or another terrains don't reset after you run the app void OnApplicationQuit() { if (Debug.isDebugBuild) { terr.terrainData.SetHeights(0, 0, heightMapBackup); terr.terrainData.SetAlphamaps(0, 0, alphaMapBackup); } }
protected void DeformTerrain(Vector3 pos, float craterSizeInMeters) { //get the heights only once keep it and reuse, precalculate as much as possible Vector3 terrainPos = GetRelativeTerrainPositionFromPos(pos,terr,hmWidth,hmHeight);//terr.terrainData.heightmapResolution/terr.terrainData.heightmapWidth int heightMapCraterWidth = (int)(craterSizeInMeters * (hmWidth / terr.terrainData.size.x)); int heightMapCraterLength = (int)(craterSizeInMeters * (hmHeight / terr.terrainData.size.z)); int heightMapStartPosX = (int)(terrainPos.x - (heightMapCraterWidth / 2)); int heightMapStartPosZ = (int)(terrainPos.z - (heightMapCraterLength / 2));
// we set each sample of the terrain in the size to the desired height for (int i = 0; i < heightMapCraterLength; i++) //width { for (int j = 0; j < heightMapCraterWidth; j++) //height { circlePosX = (j - (heightMapCraterWidth / 2)) / (hmWidth / terr.terrainData.size.x); circlePosY = (i - (heightMapCraterLength / 2)) / (hmHeight / terr.terrainData.size.z); distanceFromCenter = Mathf.Abs(Mathf.Sqrt(circlePosX * circlePosX + circlePosY * circlePosY)); //convert back to values without skew
protected Vector3 GetNormalizedPositionRelativeToTerrain(Vector3 pos, Terrain terrain) { //code based on: http://answers.unity3d.com/questions/3633/modifying-terrain-height-under-a-gameobject-at-runtime // get the normalized position of this game object relative to the terrain Vector3 tempCoord = (pos - terrain.gameObject.transform.position); Vector3 coord; coord.x = tempCoord.x / terr.terrainData.size.x; coord.y = tempCoord.y / terr.terrainData.size.y; coord.z = tempCoord.z / terr.terrainData.size.z;
return coord; }
protected Vector3 GetRelativeTerrainPositionFromPos(Vector3 pos,Terrain terrain, int mapWidth, int mapHeight) { Vector3 coord = GetNormalizedPositionRelativeToTerrain(pos, terrain); // get the position of the terrain heightmap where this game object is return new Vector3((coord.x * mapWidth), 0, (coord.z * mapHeight)); } }
MissingReferenceException: The variable m_TerrainData of 'Terrain' doesn't exist anymore. You probably need to reassign the m_TerrainData variable of the 'Terrain' script in the inspector. TerrainDeformer.Start () (at Assets/GameAssets/Scripts/TerrainDeformer.cs:48)
Код
// TerrainDeformer - Demonstrating a method modifying terrain in real-time. Changing height and texture // // released under MIT License // http://www.opensource.org/licenses/mit-license.php // //@author Devin Reimer //@website http://blog.almostlogical.com //Copyright (c) 2010 Devin Reimer /* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ using UnityEngine; using System.Collections;
public class TerrainDeformer : MonoBehaviour { public int terrainDeformationTextureNum = 1; private Terrain terr; // terrain to modify protected int hmWidth; // heightmap width protected int hmHeight; // heightmap height protected int alphaMapWidth; protected int alphaMapHeight; protected int numOfAlphaLayers; protected const float DEPTH_METER_CONVERT=0.05f; protected const float TEXTURE_SIZE_MULTIPLIER = 1.25f; private float[,] heightMapBackup; private float[, ,] alphaMapBackup;
//this has to be done because terrains for some reason or another terrains don't reset after you run the app void OnApplicationQuit() { if (Debug.isDebugBuild) { terr.terrainData.SetHeights(0, 0, heightMapBackup); terr.terrainData.SetAlphamaps(0, 0, alphaMapBackup); } }
protected void DeformTerrain(Vector3 pos, float craterSizeInMeters) { //get the heights only once keep it and reuse, precalculate as much as possible Vector3 terrainPos = GetRelativeTerrainPositionFromPos(pos,terr,hmWidth,hmHeight);//terr.terrainData.heightmapResolution/terr.terrainData.heightmapWidth int heightMapCraterWidth = (int)(craterSizeInMeters * (hmWidth / terr.terrainData.size.x)); int heightMapCraterLength = (int)(craterSizeInMeters * (hmHeight / terr.terrainData.size.z)); int heightMapStartPosX = (int)(terrainPos.x - (heightMapCraterWidth / 2)); int heightMapStartPosZ = (int)(terrainPos.z - (heightMapCraterLength / 2));
// we set each sample of the terrain in the size to the desired height for (int i = 0; i < heightMapCraterLength; i++) //width { for (int j = 0; j < heightMapCraterWidth; j++) //height { circlePosX = (j - (heightMapCraterWidth / 2)) / (hmWidth / terr.terrainData.size.x); circlePosY = (i - (heightMapCraterLength / 2)) / (hmHeight / terr.terrainData.size.z); distanceFromCenter = Mathf.Abs(Mathf.Sqrt(circlePosX * circlePosX + circlePosY * circlePosY)); //convert back to values without skew
protected Vector3 GetNormalizedPositionRelativeToTerrain(Vector3 pos, Terrain terrain) { //code based on: http://answers.unity3d.com/questions/3633/modifying-terrain-height-under-a-gameobject-at-runtime // get the normalized position of this game object relative to the terrain Vector3 tempCoord = (pos - terrain.gameObject.transform.position); Vector3 coord; coord.x = tempCoord.x / terr.terrainData.size.x; coord.y = tempCoord.y / terr.terrainData.size.y; coord.z = tempCoord.z / terr.terrainData.size.z;
return coord; }
protected Vector3 GetRelativeTerrainPositionFromPos(Vector3 pos,Terrain terrain, int mapWidth, int mapHeight) { Vector3 coord = GetNormalizedPositionRelativeToTerrain(pos, terrain); // get the position of the terrain heightmap where this game object is return new Vector3((coord.x * mapWidth), 0, (coord.z * mapHeight)); } }
подскажите а можно сделать разрушаемый ландшафт как в примере в самом начале статьи, Только в некоторых частях террейна? Тоесть не делать весь террейн разрушаемый а только в некоторых участках?