فهرست منبع

ported 3d physics examples to lua

LennyPenny 11 سال پیش
والد
کامیت
53d96c637a
25فایلهای تغییر یافته به همراه423 افزوده شده و 0 حذف شده
  1. 8 0
      Examples/Lua/3D_Physics/3DPhysics_Basic/3DPhysics_Basic.polyproject
  2. BIN
      Examples/Lua/3D_Physics/3DPhysics_Basic/Resources/green_texture.png
  3. BIN
      Examples/Lua/3D_Physics/3DPhysics_Basic/Resources/pink_texture.png
  4. 17 0
      Examples/Lua/3D_Physics/3DPhysics_Basic/Scripts/Main.lua
  5. 8 0
      Examples/Lua/3D_Physics/3DPhysics_Character/3DPhysics_Character.polyproject
  6. BIN
      Examples/Lua/3D_Physics/3DPhysics_Character/Resources/green_texture.png
  7. BIN
      Examples/Lua/3D_Physics/3DPhysics_Character/Resources/pink_texture.png
  8. 102 0
      Examples/Lua/3D_Physics/3DPhysics_Character/Scripts/Main.lua
  9. 8 0
      Examples/Lua/3D_Physics/3DPhysics_CollisionOnly/3DPhysics_CollisionOnly.polyproject
  10. BIN
      Examples/Lua/3D_Physics/3DPhysics_CollisionOnly/Resources/green_texture.png
  11. BIN
      Examples/Lua/3D_Physics/3DPhysics_CollisionOnly/Resources/pink_texture.png
  12. 33 0
      Examples/Lua/3D_Physics/3DPhysics_CollisionOnly/Scripts/Main.lua
  13. 8 0
      Examples/Lua/3D_Physics/3DPhysics_Contacts/3DPhysics_Contacts.polyproject
  14. BIN
      Examples/Lua/3D_Physics/3DPhysics_Contacts/Resources/green_texture.png
  15. BIN
      Examples/Lua/3D_Physics/3DPhysics_Contacts/Resources/hit.wav
  16. BIN
      Examples/Lua/3D_Physics/3DPhysics_Contacts/Resources/pink_texture.png
  17. 30 0
      Examples/Lua/3D_Physics/3DPhysics_Contacts/Scripts/Main.lua
  18. 8 0
      Examples/Lua/3D_Physics/3DPhysics_RayTest/3DPhysics_RayTest.polyproject
  19. BIN
      Examples/Lua/3D_Physics/3DPhysics_RayTest/Resources/green_texture.png
  20. BIN
      Examples/Lua/3D_Physics/3DPhysics_RayTest/Resources/pink_texture.png
  21. 53 0
      Examples/Lua/3D_Physics/3DPhysics_RayTest/Scripts/Main.lua
  22. 8 0
      Examples/Lua/3D_Physics/3DPhysics_Vehicle/3DPhysics_Vehicle.polyproject
  23. BIN
      Examples/Lua/3D_Physics/3DPhysics_Vehicle/Resources/green_texture.png
  24. BIN
      Examples/Lua/3D_Physics/3DPhysics_Vehicle/Resources/pink_texture.png
  25. 140 0
      Examples/Lua/3D_Physics/3DPhysics_Vehicle/Scripts/Main.lua

+ 8 - 0
Examples/Lua/3D_Physics/3DPhysics_Basic/3DPhysics_Basic.polyproject

@@ -0,0 +1,8 @@
+<?xml version="1.0" ?>
+<PolycodeProject defaultWidth="640" defaultHeight="480" antiAliasingLevel="0" entryPoint="Scripts/Main.lua" textureFiltering="linear" vSync="false" anisotropyLevel="0" frameRate="60">
+    <backgroundColor red="0.25" green="0.25" blue="0.25" />
+    <packedItems>
+        <item type="folder" path="Resources" />
+        <item type="folder" path="Scripts" />
+    </packedItems>
+</PolycodeProject>

BIN
Examples/Lua/3D_Physics/3DPhysics_Basic/Resources/green_texture.png


BIN
Examples/Lua/3D_Physics/3DPhysics_Basic/Resources/pink_texture.png


+ 17 - 0
Examples/Lua/3D_Physics/3DPhysics_Basic/Scripts/Main.lua

@@ -0,0 +1,17 @@
+scene = PhysicsScene(0, Vector3(200, 200, 200))
+
+ground = ScenePrimitive(ScenePrimitive.TYPE_PLANE, 10, 10)
+ground:loadTexture("Resources/green_texture.png")
+scene:addPhysicsChild(ground, 6, 0.0);
+
+for i = 1, 100 do
+	local box = ScenePrimitive(ScenePrimitive.TYPE_BOX, 0.5, 0.5, 0.5)
+	box:loadTexture("Resources/pink_texture.png")
+	box:Roll(-45 + math.random() % 90)
+	box:Pitch(-45 + math.random() % 90)
+	box:setPosition(-2 + math.random() % 4, i*0.5, -2 + math.random() % 4)
+	scene:addPhysicsChild(box, 0, 1.0)
+end
+
+scene:getDefaultCamera():setPosition(7, 7, 7)
+scene:getDefaultCamera():lookAt(Vector3(0, 0, 0), Vector3(1, 1, 1))

+ 8 - 0
Examples/Lua/3D_Physics/3DPhysics_Character/3DPhysics_Character.polyproject

@@ -0,0 +1,8 @@
+<?xml version="1.0" ?>
+<PolycodeProject defaultWidth="640" defaultHeight="480" antiAliasingLevel="0" entryPoint="Scripts/Main.lua" textureFiltering="linear" vSync="false" anisotropyLevel="0" frameRate="60">
+    <backgroundColor red="0.25" green="0.25" blue="0.25" />
+    <polyarray:packedItems>
+        <item type="folder" path="Resources" />
+        <item type="folder" path="Scripts" />
+    </polyarray:packedItems>
+</PolycodeProject>

BIN
Examples/Lua/3D_Physics/3DPhysics_Character/Resources/green_texture.png


BIN
Examples/Lua/3D_Physics/3DPhysics_Character/Resources/pink_texture.png


+ 102 - 0
Examples/Lua/3D_Physics/3DPhysics_Character/Scripts/Main.lua

@@ -0,0 +1,102 @@
+scene = PhysicsScene(0, Vector3(200, 200, 200))
+
+ground = ScenePrimitive(ScenePrimitive.TYPE_PLANE, 10, 10)
+ground:loadTexture("Resources/green_texture.png")
+
+scene:addPhysicsChild(ground, 6, 0)
+
+for i = 1, 1 do
+	local box = ScenePrimitive(ScenePrimitive.TYPE_BOX, 0.8, 0.8, 0.8)
+	box:loadTexture("Resources/pink_texture.png")
+	box:Roll(-45 + math.random() % 90)
+	box:Pitch(-45 + math.random() % 90)
+	box:setPosition(-2 + math.random() % 4, i * 0.5, -2 + math.random() % 4)
+
+	scene:addPhysicsChild(box, 0, 1)
+end
+
+player = ScenePrimitive(ScenePrimitive.TYPE_BOX, 0.5, 1, 0.5)
+player:loadTexture("Resources/pink_texture.png")
+player:setColor(1, 1, 0, 1)
+player:setPosition(2, 1, 2)
+
+playerController = scene:addCharacterChild(player, 10, 1, 0.5)
+local walkSpeed = 0
+local rotateSpeed = 0
+local playerDirection = 0
+
+testBox = ScenePrimitive(ScenePrimitive.TYPE_BOX, 2, 2, 2)
+testBox:loadTexture("Resources/pink_texture.png")
+testBox:setColor(0.3, 0.5, 1, 0.4)
+testBox:setPosition(2,1,-2)
+
+scene:addCollisionChild(testBox, 0)
+	
+hud = Scene(Scene.SCENE_2D_TOPLEFT)
+onGroundLabel = SceneLabel("Arrow keys to control, spacebar to jump, press R to reset", 16)
+onGroundLabel:setAnchorPoint(Vector3(-1, -1, 0))
+onGroundLabel:setPosition(0,0)
+hud:addChild(onGroundLabel)
+onGroundLabel = SceneLabel("On Ground:", 16)
+onGroundLabel:setAnchorPoint(Vector3(-1, -1, 0))
+onGroundLabel:setPosition(0, 32)
+
+hud:addChild(onGroundLabel)
+
+
+scene:getDefaultCamera():setPosition(7, 7, 7)
+scene:getDefaultCamera():lookAt(Vector3(0, 0, 0), Vector3(1, 1, 1))
+
+function handleKeyEvent(t, e)
+	if not e:getDispatcher() == CoreServices.getInstance():getCore():getInput() then return end
+
+	local inputEvent = safe_cast(e, InputEvent)
+	
+	local eventKeyCode = e:getEventCode()
+	if eventKeyCode == InputEvent.EVENT_KEYDOWN then
+		local keyCode = inputEvent:keyCode()
+
+		if keyCode == KEY_r then
+			playerController:warpCharacter(Vector3(2, 1, 2))
+		elseif keyCode == KEY_UP then
+			walkSpeed = 0.05
+		elseif keyCode == KEY_DOWN then
+			walkSpeed = -0.05
+		elseif keyCode == KEY_LEFT then
+			rotateSpeed = 3
+		elseif keyCode == KEY_RIGHT then
+			rotateSpeed = -3
+		elseif keyCode == KEY_SPACE then
+			playerController:jump()
+		end
+	elseif eventKeyCode == InputEvent.EVENT_KEYUP then
+		if inputEvent.key == KEY_DOWN then
+			walkSpeed = 0
+		elseif inputEvent.key == KEY_RIGHT then
+			rotateSpeed = 0
+		end
+	end
+end
+
+CoreServices.getInstance():getCore():getInput():addEventListener(nil, handleKeyEvent, InputEvent.EVENT_KEYDOWN)
+CoreServices.getInstance():getCore():getInput():addEventListener(nil, handleKeyEvent, InputEvent.EVENT_KEYUP)
+
+function Update(elapsed)
+	playerDirection = playerDirection + rotateSpeed * elapsed
+	
+	player:setYaw(playerDirection * (180 / math.pi))
+	playerController:setWalkDirection(Vector3(walkSpeed * math.cos(playerDirection), 0, walkSpeed * math.sin(-playerDirection)))
+	
+	if playerController:onGround() then
+		onGroundLabel:setText("On Ground: YES")
+	else
+		onGroundLabel:setText("On Ground: NO")	
+	end
+	
+	res = scene:testCollision(player, testBox)
+	if res.collided then
+		testBox:setColor(1, 1, 0, 0.5)		
+	else
+		testBox:setColor(0, 1, 1, 0.5)	
+	end
+end

+ 8 - 0
Examples/Lua/3D_Physics/3DPhysics_CollisionOnly/3DPhysics_CollisionOnly.polyproject

@@ -0,0 +1,8 @@
+<?xml version="1.0" ?>
+<PolycodeProject defaultWidth="640" defaultHeight="480" antiAliasingLevel="0" entryPoint="Scripts/Main.lua" textureFiltering="linear" vSync="false" anisotropyLevel="0" frameRate="60">
+    <backgroundColor red="0.25" green="0.25" blue="0.25" />
+    <polyarray:packedItems>
+        <item type="folder" path="Resources" />
+        <item type="folder" path="Scripts" />
+    </polyarray:packedItems>
+</PolycodeProject>

BIN
Examples/Lua/3D_Physics/3DPhysics_CollisionOnly/Resources/green_texture.png


BIN
Examples/Lua/3D_Physics/3DPhysics_CollisionOnly/Resources/pink_texture.png


+ 33 - 0
Examples/Lua/3D_Physics/3DPhysics_CollisionOnly/Scripts/Main.lua

@@ -0,0 +1,33 @@
+scene =  CollisionScene(Vector3(2000, 2000, 2000), false, false)
+
+ground = ScenePrimitive(ScenePrimitive.TYPE_PLANE, 10, 10)
+ground:loadTexture("Resources/green_texture.png")
+scene:addEntity(ground)
+
+box = ScenePrimitive(ScenePrimitive.TYPE_BOX, 0.5, 0.5, 0.5)
+box:loadTexture("Resources/pink_texture.png")
+box:setPosition(0, 1, 0)
+scene:addCollisionChild(box, CollisionEntity.SHAPE_BOX)
+
+bigBox = ScenePrimitive(ScenePrimitive.TYPE_BOX, 2, 2, 2)
+bigBox:loadTexture("Resources/pink_texture.png")
+bigBox:setColor(0, 1, 1, 0.5)
+bigBox:setPosition(0, 1, 0)
+scene:addCollisionChild(bigBox, CollisionEntity.SHAPE_BOX)
+
+
+scene:getDefaultCamera():setPosition(7, 7, 7)
+scene:getDefaultCamera():lookAt(Vector3(0, 0, 0), Vector3(1, 1, 1))
+
+local swingValue = 0
+
+function Update(elapsed)
+	swingValue = swingValue + elapsed
+	box:setPosition(math.sin(swingValue) * 5, 1, 0)	
+	
+	if scene:testCollision(box, bigBox).collided then
+		bigBox:setColor(1, 1, 0, 0)		
+	else
+		bigBox:setColor(0, 1, 1, 0.5)	
+	end
+end

+ 8 - 0
Examples/Lua/3D_Physics/3DPhysics_Contacts/3DPhysics_Contacts.polyproject

@@ -0,0 +1,8 @@
+<?xml version="1.0" ?>
+<PolycodeProject defaultWidth="640" defaultHeight="480" antiAliasingLevel="0" entryPoint="Scripts/Main.lua" textureFiltering="linear" vSync="false" anisotropyLevel="0" frameRate="60">
+    <backgroundColor red="0.25" green="0.25" blue="0.25" />
+    <polyarray:packedItems>
+        <item type="folder" path="Resources" />
+        <item type="folder" path="Scripts" />
+    </polyarray:packedItems>
+</PolycodeProject>

BIN
Examples/Lua/3D_Physics/3DPhysics_Contacts/Resources/green_texture.png


BIN
Examples/Lua/3D_Physics/3DPhysics_Contacts/Resources/hit.wav


BIN
Examples/Lua/3D_Physics/3DPhysics_Contacts/Resources/pink_texture.png


+ 30 - 0
Examples/Lua/3D_Physics/3DPhysics_Contacts/Scripts/Main.lua

@@ -0,0 +1,30 @@
+scene = PhysicsScene(0, Vector3(200, 200, 200))
+
+ground = ScenePrimitive(ScenePrimitive.TYPE_PLANE, 10, 10)
+ground:loadTexture("Resources/green_texture.png")
+
+scene:addPhysicsChild(ground, 6, 0)
+
+for i = 1, 100 do
+	local box = ScenePrimitive(ScenePrimitive.TYPE_BOX, 0.5,0.5,0.5)
+	box:loadTexture("Resources/pink_texture.png")
+	box:Roll(-45 + math.random() % 90)
+	box:Pitch(-45 + math.random() % 90)		
+	box:setPosition(-2 + math.random() % 4, i*0.5, -2 + math.random() % 4)
+
+	scene:addPhysicsChild(box, 0, 1)
+end
+
+scene:getDefaultCamera():setPosition(7, 7, 7)
+scene:getDefaultCamera():lookAt(Vector3(0, 0, 0), Vector3(1, 1, 1))
+
+collisionSound = Sound("Resources/hit.wav")
+
+function onCollisionEvent(t, event)
+	if not event:getDispatcher() == scene then return end
+
+	if safe_cast(event, PhysicsSceneEvent).physEvent.appliedImpulse > 2 then
+			collisionSound:Play()
+	end
+end
+scene:addEventListener(nil, onCollisionEvent, PhysicsSceneEvent.COLLISION_EVENT)

+ 8 - 0
Examples/Lua/3D_Physics/3DPhysics_RayTest/3DPhysics_RayTest.polyproject

@@ -0,0 +1,8 @@
+<?xml version="1.0" ?>
+<PolycodeProject defaultWidth="640" defaultHeight="480" antiAliasingLevel="0" entryPoint="Scripts/Main.lua" textureFiltering="linear" vSync="false" anisotropyLevel="0" frameRate="60">
+    <backgroundColor red="0.25" green="0.25" blue="0.25" />
+    <polyarray:packedItems>
+        <item type="folder" path="Resources" />
+        <item type="folder" path="Scripts" />
+    </polyarray:packedItems>
+</PolycodeProject>

BIN
Examples/Lua/3D_Physics/3DPhysics_RayTest/Resources/green_texture.png


BIN
Examples/Lua/3D_Physics/3DPhysics_RayTest/Resources/pink_texture.png


+ 53 - 0
Examples/Lua/3D_Physics/3DPhysics_RayTest/Scripts/Main.lua

@@ -0,0 +1,53 @@
+hud = Scene(Scene.SCENE_2D)
+
+label = SceneLabel("Click on a shape to select it.", 16)
+label:setPosition(-640/ 2 + 120, 480 / 2 - 10)
+
+hud:addChild(label)
+
+scene = CollisionScene(Vector3(2000, 2000, 2000), false, false)
+
+local ground = ScenePrimitive(ScenePrimitive.TYPE_PLANE, 10, 10)
+ground:loadTexture("Resources/green_texture.png")
+scene:addEntity(ground)
+
+local box = ScenePrimitive(ScenePrimitive.TYPE_BOX, 1, 1, 1)
+box:loadTexture("Resources/pink_texture.png")
+box:setPosition(0, 1, 0)
+scene:addCollisionChild(box, CollisionEntity.SHAPE_MESH)
+
+local cone = ScenePrimitive(ScenePrimitive.TYPE_CONE, 1, 1, 10)
+cone:loadTexture("Resources/pink_texture.png")
+cone:setPosition(1, 2, 2)
+scene:addCollisionChild(cone, CollisionEntity.SHAPE_CONE)
+
+local cylinder = ScenePrimitive(ScenePrimitive.TYPE_CYLINDER, 2, 0.5, 10)
+cylinder:loadTexture("Resources/pink_texture.png")
+cylinder:setPosition(2, 1, -1)
+scene:addCollisionChild(cylinder, CollisionEntity.SHAPE_CYLINDER)
+
+
+scene:getDefaultCamera():setPosition(7, 7, 7)
+scene:getDefaultCamera():lookAt(Vector3(0, 0, 0), Vector3(1, 1, 1))
+
+local lastEntity = nil
+function mouseDownEvent(t, e)
+	if not e:getDispatcher() == CoreServices.getInstance():getCore():getInput() then return end
+
+	local inputEvent = safe_cast(e, InputEvent)
+
+	if e:getEventCode() == InputEvent.EVENT_MOUSEDOWN then
+        local ray = scene:projectRayFromCameraAndViewportCoordinate(scene:getActiveCamera(), inputEvent.mousePosition)
+		local res = scene:getFirstEntityInRay(ray.origin, Vector3(ray.direction.x * 100, ray.direction.y * 100, ray.direction.z * 100))
+
+		if lastEntity then
+			lastEntity:setColor(1, 1, 1, 1)
+		end
+
+		if res.entity then
+			res.entity:setColor(1, 0, 0, 1)
+			lastEntity = res.entity
+		end
+	end
+end
+CoreServices.getInstance():getCore():getInput():addEventListener(nil, mouseDownEvent, InputEvent.EVENT_MOUSEDOWN)

+ 8 - 0
Examples/Lua/3D_Physics/3DPhysics_Vehicle/3DPhysics_Vehicle.polyproject

@@ -0,0 +1,8 @@
+<?xml version="1.0" ?>
+<PolycodeProject defaultWidth="640" defaultHeight="480" antiAliasingLevel="0" entryPoint="Scripts/Main.lua" textureFiltering="linear" vSync="false" anisotropyLevel="0" frameRate="60">
+    <backgroundColor red="0.25" green="0.25" blue="0.25" />
+    <polyarray:packedItems>
+        <item type="folder" path="Resources" />
+        <item type="folder" path="Scripts" />
+    </polyarray:packedItems>
+</PolycodeProject>

BIN
Examples/Lua/3D_Physics/3DPhysics_Vehicle/Resources/green_texture.png


BIN
Examples/Lua/3D_Physics/3DPhysics_Vehicle/Resources/pink_texture.png


+ 140 - 0
Examples/Lua/3D_Physics/3DPhysics_Vehicle/Scripts/Main.lua

@@ -0,0 +1,140 @@
+scene = PhysicsScene(0, Vector3(200, 200, 200))
+
+ground = ScenePrimitive(ScenePrimitive.TYPE_PLANE, 30, 30)
+ground:loadTexture("Resources/green_texture.png")
+scene:addPhysicsChild(ground, 0, 0)
+
+-- Some obstacles
+local box = ScenePrimitive(ScenePrimitive.TYPE_BOX, 4,4,6)
+box:setPitch(25)
+box:setPosition(7, -15, 0)
+box:setColor(0.5, 0.5, 1,1)
+box:loadTexture("Resources/green_texture.png")
+scene:addPhysicsChild(box, 0, 0)
+
+box = ScenePrimitive(ScenePrimitive.TYPE_BOX, 4, 4, 6)
+box:setPitch(25)
+box:setPosition(-7,-15, 0)
+box:setColor(0.5,0.5,1,1)
+box:loadTexture("Resources/green_texture.png")
+scene:addPhysicsChild(box, 0, 0)
+
+box = ScenePrimitive(ScenePrimitive.TYPE_BOX, 20,2,5)
+box:setPosition(0,1, -4.3)
+box:setColor(0.5,0.5,1,1)
+box:loadTexture("Resources/green_texture.png")
+scene:addPhysicsChild(box, 0, 0)
+
+for i = 1, 10 do
+	box = ScenePrimitive(ScenePrimitive.TYPE_BOX, 0.7,0.7,0.7)
+	box:loadTexture("Resources/pink_texture.png")
+	box:Roll(-45 + math.random() % 90)
+	box:Pitch(-45 + (math.random() % 90))
+	box:setPosition(-3 + (math.random() % 6), 2 + i*0.5, -5 + math.random() % 3)
+	scene:addPhysicsChild(box, 0, 1)
+end
+
+-- The vehicle
+vehicle = ScenePrimitive(ScenePrimitive.TYPE_BOX, 1, 0.5, 2)
+vehicle:loadTexture("Resources/pink_texture.png")
+vehicle:setColor(1, 1, 0, 1)
+vehicle:setPosition(6,1,5)
+vehicleController = scene:addVehicleChild(vehicle, 5, 1)
+
+local wheel = ScenePrimitive(ScenePrimitive.TYPE_SPHERE, 0.3, 10, 10)
+wheel:loadTexture("Resources/pink_texture.png")
+wheel:setColor(0, 1, 0, 1)
+vehicleController:addWheel(wheel, Vector3(0.6, 0, -0.5), Vector3(0, -1, 0), Vector3(-1,0,0), 0.2, 0.3, true)
+scene:addEntity(wheel)
+
+wheel = ScenePrimitive(ScenePrimitive.TYPE_SPHERE, 0.3, 10, 10)
+wheel:loadTexture("Resources/pink_texture.png")
+wheel:setColor(0, 1, 0, 1)
+vehicleController:addWheel(wheel, Vector3(-0.6,0,-0.5), Vector3(0,-1,0), Vector3(-1,0,0), 0.2, 0.3, true)
+scene:addEntity(wheel)
+
+wheel = ScenePrimitive(ScenePrimitive.TYPE_SPHERE, 0.3, 10, 10)
+wheel:loadTexture("Resources/pink_texture.png")
+wheel:setColor(0, 1, 0, 1)
+vehicleController:addWheel(wheel, Vector3(0.6,0,0.5), Vector3(0,-1,0), Vector3(-1,0,0), 0.2, 0.3, false)
+scene:addEntity(wheel)
+
+wheel = ScenePrimitive(ScenePrimitive.TYPE_SPHERE, 0.3, 10, 10)
+wheel:loadTexture("Resources/pink_texture.png")
+wheel:setColor(0, 1, 0, 1)
+vehicleController:addWheel(wheel, Vector3(-0.6,0,0.5), Vector3(0,-1,0), Vector3(-1,0,0), 0.2, 0.3, false)
+scene:addEntity(wheel)
+
+local steeringValue = 0
+local engineForce = 0
+local breaking = false
+
+local testBox = ScenePrimitive(ScenePrimitive.TYPE_BOX, 4, 4, 4)
+testBox:loadTexture("Resources/pink_texture.png")
+testBox:setColor(0.3, 0.5, 1, 0.4)
+testBox:setPosition(-5, 2, 7)
+scene:addCollisionChild(testBox, 0)
+
+
+scene:getDefaultCamera():setPosition(16, 16, 16)
+scene:getDefaultCamera():lookAt(Vector3(0, 0, 0), Vector3(1, 1, 1))
+
+local function handleKeyEvent(t, e)
+	if not e:getDispatcher() == CoreServices.getInstance():getCore():getInput() then return end
+	
+	local inputEvent = safe_cast(e, InputEvent)
+	
+	local eventKeyCode = e:getEventCode()
+	if eventKeyCode == InputEvent.EVENT_KEYDOWN then
+		local keyCode = inputEvent:keyCode()
+
+		if keyCode == KEY_r then
+			vehicleController:warpVehicle(Vector3(6,1,5))
+		elseif keyCode == KEY_UP then
+			engineForce = -15
+		elseif keyCode == KEY_DOWN then
+			engineForce = 15
+		elseif keyCode == KEY_LEFT then
+			steeringValue = 0.5
+		elseif keyCode == KEY_RIGHT then
+			steeringValue = -0.5
+		elseif keyCode == KEY_SPACE then
+			breaking = true
+		end
+	elseif eventKeyCode == InputEvent.EVENT_KEYUP then
+		if inputEvent.key == KEY_DOWN then
+			engineForce = 0	
+		elseif inputEvent.key == KEY_RIGHT then
+			steeringValue = 0
+		elseif inputEvent.key == KEY_SPACE then
+			breaking = false
+		end
+	end
+end
+CoreServices.getInstance():getCore():getInput():addEventListener(nil, handleKeyEvent, InputEvent.EVENT_KEYDOWN)
+CoreServices.getInstance():getCore():getInput():addEventListener(nil, handleKeyEvent, InputEvent.EVENT_KEYUP)
+
+function Update(elapsed)
+	
+	if breaking then
+		vehicleController:setBrake(20, 2)
+		vehicleController:setBrake(20, 3)
+		vehicleController:applyEngineForce(0, 2)
+		vehicleController:applyEngineForce(0, 3)
+	else
+		vehicleController:setBrake(0, 2)
+		vehicleController:setBrake(0, 3)
+		vehicleController:applyEngineForce(engineForce, 2)
+		vehicleController:applyEngineForce(engineForce, 3)
+	end
+	
+	vehicleController:setSteeringValue(steeringValue, 0)
+	vehicleController:setSteeringValue(steeringValue, 1)
+	
+	local res = scene:testCollision(vehicle, testBox)
+	if res.collided then
+		testBox:setColor(1,1,0,0.5)
+	else
+		testBox:setColor(0,1,1,0.5)
+	end
+end