Weird terrain behaviour

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
chebob69
Posts: 40
Joined: Thu Aug 16, 2012 7:27 pm

Weird terrain behaviour

Post by chebob69 »

Ok I'm hoping you can tell me what's going on with my terrain, cos I'm frankly stumped.
I've created a terrain with the following code (where 'heightMap' is a 64x64 float array)

Code: Select all

terrain = new Terrain(heightMap, new AffineTransform(new Vector3(4, 1, 4),Quaternion.Identity,new Vector3(-64 * 4 / 2, 0, -64 * 4 / 2)));
So this SHOULD make a terrain with 64 vertices length and widthways with a 4m gap between each of them. Is that right? It's then translated so it's centered about the origin.
I have a visual mesh that aligns exactly with the terrain collidable (for texturing). This seems to match it as it should (if I drop a ball on it, it 'appears' to react with the visual mesh).
Now comes the weird part. I have 2 raycasts, 1 going from the camera location in the direction of the mouse pointer and 1 going directly downwards from the camera so the camera
conforms to the terrain height. Both of these raycasts return false whenever they hit the terrain (or where the terrain should be) past x=124 or z=124. (e.g x=124.1, z=2 returns false AND x=56, z=124.5 returns false). So if I place a ball at x=120 z=20 on the terrain and watch it roll downhill, it does so perfectly for a moment and then falls through the terrain when it gets to x=124.

Help!
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Weird terrain behaviour

Post by Norbo »

A terrain created from 64x64 vertex heights will have 63x63 quads. Given a position of (-128, 0, -128), the maximum horizontal vertex location will be -128 + 63 * 4 = 124.

The BEPUphysicsDrawer from the main source download can help with visualizing the actual collision geometry.
chebob69
Posts: 40
Joined: Thu Aug 16, 2012 7:27 pm

Re: Weird terrain behaviour

Post by chebob69 »

Aha, excellent. I figured it was something along those lines. I'm slightly unsure why it seems to fit my visual mesh correctly for the rest of it though- since the visual mesh carries on past the
124 mark. Bit odd. I'll have a look at the physicsDrawer anyway and report back!
Thanks Norbo
Post Reply