- Home /
Enemy Avoid Terrain
Hey guys, I have an helicopter enemy script that moves towards the player. Does anyone know how to make the helicopter avoid the terrain as the helicopter enemy is going through a mountain i created. Thanks :D Johnny
you can try doing raycast so he's above the grownd so that helicopter tries to add transform.position up if length of raycast is too low
I'm not expert of rays tho but my thinking is in that way
the otherway would be figuering out the terrain height and adding on that 2 distances
you'll need to do a bit of math for that as terrain heights don't have meters
this is how I find at what possition I'm on terrain and I'm lowering that point a bit
using UnityEngine;
using System.Collections;
[System.Serializable]
public class Terraform : $$anonymous$$onoBehaviour {
public Terrain terrain ;
public TerrainData tData;
public int xRes ;
public int yRes ;
public float[,] heights;
public int PlayerXi ;
public int PlayerZi ;
private GameObject Player ;
void Start () {
Player = GameObject.Find("Camera") ;
tData = terrain.terrainData;
xRes = tData.heightmapWidth;
yRes = tData.heightmapHeight;
//terrain.activeTerrain.heightmap$$anonymous$$aximumLOD = 0;
}
void On$$anonymous$$ouseDown() {
PlayerXi = (int) Player.transform.position.x;
PlayerZi = (int) Player.transform.position.z;
heights = tData.GetHeights(0, 0, xRes, yRes);
// Z is X //// X is Y
heights[PlayerZi,PlayerXi] -= 0.004f ;
tData.SetHeights(0, 0, heights);
}
}
Your answer
Follow this Question
Related Questions
Make player not be seen by AI, when player in foilage and shadows. 1 Answer
Enemy AI C# 0 Answers
Why doesn't this AI script work? c# 1 Answer
Stopping AI's animation and movement 0 Answers
zombie enemy AI 1 Answer