Topic: Terrain collisions
I'm trying to have a model walk over a terrain, but I ran into a problem, the player seems to get stuck on very little slopes of the terrain.
In the Irrlicht forums there were some people with the same problem, but I still couldn't get it fixed.
Here is a simple example I threw together:
SuperStrict
Framework BRL.Blitz
Import BRL.StandardIO
Import Irrlicht.Core
' player cube
Global player:ISceneNode
' for handling user input
Type MyEventReceiver Extends IEventReceiver
Field Terrain:ISceneNode
Method setTerrain(terr:ISceneNode)
Terrain=terr
EndMethod
Method OnEvent:Int(event:SEvent)
' check If user presses the key 'W' or 'D'
If event.getEventType()=EET_KEY_INPUT_EVENT
Local key:Int=event.getKeyInputKey()
Select key
' move forward
Case EKEY_KEY_W
Local p:vector3df=player.getPosition()
Local v:vector3df=_VECTOR3DF(p.getX(),p.getY(),p.getZ()+20)
player.setPosition(v)
Return True
' move backward
Case EKEY_KEY_S
Local p:vector3df=player.getPosition()
Local v:vector3df=_VECTOR3DF(p.getX(),p.getY()-0.2,p.getZ()-20)
player.setPosition(v)
Return True
EndSelect
EndIf
Return False
EndMethod
Function generate:IEventReceiver()
Return New MyEventReceiver
EndFunction
EndType
Local device:IrrlichtDevice=IrrlichtDevice.create(EDT_OPENGL , _DIMENSION2DI(800,600))
If device.handle=0 Then Return
Local driver:IVideoDriver=device.getVideoDriver()
Local smgr:ISceneManager=device.getSceneManager()
Local env:IGUIEnvironment=device.getGUIEnvironment()
Local camera:ICameraSceneNode=smgr.addCameraSceneNodeFPS(Null,100.0,1200.0)
camera.setPosition(_VECTOR3DF(1900*2,255*2,3700*2))
Local terrain:ITerrainSceneNode=smgr.addTerrainSceneNodeFromFile("terrain-heightmap.bmp")
terrain.SetScale(_VECTOR3DF(40, 4.4, 40))
terrain.setMaterialFlag(EMF_LIGHTING, False)
terrain.setMaterialTexture(0, driver.getTexture("terrain-texture.jpg"))
Local selector:ITriangleSelector=smgr.createTerrainTriangleSelector(terrain, 0)
terrain.setTriangleSelector(selector)
selector.drop()
player=smgr.addCubeSceneNode()
player.setPosition(_VECTOR3DF(1900*2,255*2,3700*2))
player.setScale(_VECTOR3DF(4.0,8.0,4.0))
Local anim:ISceneNodeAnimator=smgr.createCollisionResponseAnimator( ..
selector, player, _VECTOR3DF(18,36,18), _VECTOR3DF(0,-.1,0), _VECTOR3DF(0,10,0))
player.addAnimator(anim)
Local receiver:IEventReceiver=IEventReceiver.create(MyEventReceiver.generate)
device.setEventReceiver(receiver)
While (device.run())
'start drawing everything
driver.beginScene(True,True,_SCOLOR(255,30,80,200))
smgr.drawAll()
env.drawAll()
driver.endScene()
Wend
device.drop()
It uses a heightmap 'terrain-heightmap.bmp' and a texture 'terrain-texture.jpg' wich are located in the Irrlicht media folder. (don't mind the lack of commands, I threw this together rather quickly )
Does anyone know how I can fix this?
Thanks in advantage.