A complicated, unity related math question

hey community

This is probably the wrong place to post but i was to lazy to sign up on a math forum and i thought id might get mist response here…

So my problem:

I have a 2D array, read out of a terrain (the getheights())

I also have a 3D vector where i have the x and z coordinate and i want to get the y coordinate from the array…

Since a 2D array requires integers i round the vectors x and z coordinate so i have a point in the array and i take out a 2nd (rounded x + 1) and a 3rd (rounded z + 1) out of the array

Now from these 3 points i want to get the y coordinate of the vector between those three…

Im really stuck on this question please help me guys :smile:

Btw: i cant use getheight() since i want to code this in java (real java not javascript) and i already read in the terrain heights

Greetings
/Robert

The cross product of any two vectors gives a third vector perpendicular to the plane the two vectors reside in. How you do the calculation matters x X z gives one direction z X x gives the negative 180 degree offset vector.

i dont understand a word -.- xD

“Now from these 3 points i want to get the y coordinate of the vector between those three…”

There’s no vector between 3 points. Vectors describe a straight line between two points.

What are you actually trying to accomplish here?

Probably NPC/mob position on an exported map from unity :smile:

Hi Robbilie… This is straightforward sampling of a heightmap:

try this link

You can speed this up massively with precomputed tables, but if you’re just doing a few per frame that should work fine.

btw if you also want the normals, you can just sample 4 points slightly offset and then work out the normal from those points.

hey guys

Thanks chris, u got the idea of what i need :slight_smile:

Further i need help how to do bilinear interpolation in unity…?

Thanks in advance :wink:

You can interpolate lots of data (Vectors, Quaternions, Floats, Ints, etc).

A good example of a spherical interpolation is let’s say you have an enemy heading towards the player by X amount of time, you’ll do like so (pseudo code) :

desiredRotation = Quaternion.Euler (enemyTransform.position - playerTransform.position);//get the player direction
enemyTransform.rotation = Quaternion.Slerp(enemyTransform.rotation, desiredRotation, rotateSpeed * Time.deltaTime);

From there, you can do the same with Lerp (only linear), on Vectors, etc.

Actually your code doesn’t help, because he have to do it on Java.
I suggest to look here and understand the math behind; is quite simple.

I’m just giving an example to Robblie of one of the many ways to interpolate values in Unity.
You should provably stop making no sense comments and post something useful.
I’m leaving it here, have a nice day.

Right but the op did specifically say “i cant use getheight() since i want to code this in java (real java not javascript)” :slight_smile:

I’ve modified my first post to fix my lack of reading attention regarding the Java part. ← Idiot face!
However my interpolation example with Quaternions still valid. ^^

Sry i forgot to post the link for bilinear interpolation Bilinear interpolation - Wikipedia

so i first interpolate on the x and then on the z axis?