Jump to content

Terrain collision ?


Meldrion
 Share

Recommended Posts

From editor set properties on your model like mass and Collision Type, when property windows is empty - add lua script with name like your model.

 

Note: Template script is in Scripts folder ("template.lua").

[HW] C2D Q6600, 4GB RAM, NV8800GTX, Vista Ultimate x64

[sW] Blide Plus, BlitzMax, Delphi, C++, 3DWS 5.53, Leadwerks 2.xx

 

76561197970156808.pngAndyGFX.png

Link to comment
Share on other sites

What is a collider?

 

You need to set the terrain collision type, just like any other entity.

 

But how can I set this ?

I dont know how to access the terrain that is my scene.

 

Here is the code I have made so far

--require("scripts/hooks")
require("scripts/constants/keycodes")

--Register abstract path
RegisterAbstractPath("")
--Set graphics mode
if Graphics(1024,768,0,60,0)==0 then
       Notify("Failed to set graphics mode.",1)
       return
end

-- Custom shutDown Variable
ShutDown= false

--Create framewerk object and set it to a global object so other scripts can access it
fw=CreateFramework()
if fw==nil then
       Notify("Failed to initialize engine.",1)
       return
end
SetGlobalObject("framewerk",fw)

-- Setup Initial Post Processing FX
SetGodRays(1)
SetHDR(0)
SetSSAO(0)
SetBloom(1)
SetAntialias(0)
SetNearDOF(0)
SetFarDOF(1)
SetFarDOFRange(22, 150);
SetZoom(2)

scene=LoadScene("abstract::TestSideScroll.sbx")
camera=fw.main.camera
camera:SetPositionf(0,1.5,-1.5)

-- Create the Player
player2D = CreatePlane();
--player2D:SetPosition(Vec3(0,1.5,2.5))
player2D:SetScale(Vec3(0.5,1,0.7))
player2D:SetRotation(Vec3(270,0,0))

-- Create the Collider for the Player
player2DBody = CreateBodyBox(1,1.5,1)
player2DBody:SetPosition(Vec3(0,1.5,2.5))
-- TestCollider
--playground = CreateBodyBox(5,2,5)
--playground:SetPosition(Vec3(0,0,1))

EntityParent(player2D,player2DBody)
SetBodyMass(player2DBody,0.1)

-- Only for testing
DebugPhysics(1)

-- Enable the Rain Sound Effect 
class = classnametable[ "innowork_soundcontroller" ] 
if class~=nil then  
for model,object in pairs(class.instances) do 
  object.model:SetKey("enabled","1")
  object.model:SetKey("soundfile","Regen.ogg")         
end 
end
-- Get the RainParticles
myRain = classnametable["environment_emitter"]
if myRain ~=nil then
for model,object in pairs(myRain.instances) do 
  myRainModel = object.model        
end
myRainModel:SetPosition(Vec3(0,6.5,3), 1 ) 
end

-- Control the Camera (and all object bound to it) 
function ControlCamera()
 if KeyDown (KEY_D)==1 then  
   MoveEntity (camera, Vec3(0.1*AppSpeed(),0,0))
   -- Move the Rain Particle Effect so that the Rain is allways in the 
   -- ScreenView
   if myRainModel ~=nil then  
     MoveEntity(myRainModel,Vec3(0.1*AppSpeed(),0,0)) 
   end
   -- Move the PlayerSprite
   if player2D ~=nil then
     MoveEntity(player2DBody,Vec3(0.2*AppSpeed(),0,0))
   end
 end 
 if KeyDown (KEY_A)==1 then 
   MoveEntity (camera, Vec3(-0.1*AppSpeed(),0,0))
   -- Move the Rain Particle Effect so that the Rain is allways in the 
   -- ScreenView
   if myRainModel ~=nil then 
     MoveEntity (myRainModel, Vec3(-0.1*AppSpeed(),0,0))
   end 
   -- Move the PlayerSprite
   if player2D ~=nil then
     MoveEntity(player2DBody,Vec3(-0.2*AppSpeed(),0,0))
   end 
 end
 if KeyDown(KEY_ESCAPE)==1 then 
   ShutDown=true 
 end
end

-- Collisions
Collisions(1,1,1);
EntityType(player2DBody,1)
--EntityType(playground,1)
--EntityType(terrain,1)
--
while AppTerminate()==0 and ShutDown == false do
       UpdateAppTime()
       fw:Update()
       fw:Render()
       ControlCamera()
       Flip(0)
end

 

Meldrion

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...