Added TestScene
Signed-off-by: Robear Selwans <robear.selwans@outlook.com>
This commit is contained in:
@@ -27,7 +27,11 @@
|
|||||||
{
|
{
|
||||||
"id": "SideScene",
|
"id": "SideScene",
|
||||||
"path": "scenes://SideScene.evsc"
|
"path": "scenes://SideScene.evsc"
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
"id": "TestScene",
|
||||||
|
"path": "scenes://TestScene.evsc"
|
||||||
|
},
|
||||||
],
|
],
|
||||||
"activeScene": "MainScene"
|
"activeScene": "MainScene"
|
||||||
}
|
}
|
||||||
|
|||||||
1463
res/project/res/scenes/TestScene.evsc
Normal file
1463
res/project/res/scenes/TestScene.evsc
Normal file
File diff suppressed because it is too large
Load Diff
66
res/project/res/scripts/TestScene/Camera.lua
Normal file
66
res/project/res/scripts/TestScene/Camera.lua
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
this.on_init = function()
|
||||||
|
this.speed = 2.1
|
||||||
|
this.original_position = this.position
|
||||||
|
this.angles = Vec3:new()
|
||||||
|
this.mouse_sens = 0.01
|
||||||
|
this.cursor_locked = false
|
||||||
|
end
|
||||||
|
|
||||||
|
this.toggleCursor = function()
|
||||||
|
if this.cursor_locked then
|
||||||
|
Input.unlockCursor()
|
||||||
|
else
|
||||||
|
Input.lockCursor()
|
||||||
|
end
|
||||||
|
this.cursor_locked = not this.cursor_locked
|
||||||
|
end
|
||||||
|
|
||||||
|
this.on_update = function()
|
||||||
|
local deltaMouseMovement = Input.getDeltaMousePos()
|
||||||
|
this.angles.y = this.angles.y - deltaMouseMovement.x * this.mouse_sens
|
||||||
|
this.eulerAngles = this.angles
|
||||||
|
|
||||||
|
helper = this:getChild('RotationHelper')
|
||||||
|
|
||||||
|
if Input.getKeyJustPressed(Input.KeyCode.Enter) then
|
||||||
|
gotoScene('SideScene')
|
||||||
|
end
|
||||||
|
|
||||||
|
local pos = this.position
|
||||||
|
if Input.getKeyDown(Input.KeyCode.Up) then
|
||||||
|
pos = pos + helper.forward * this.speed
|
||||||
|
end
|
||||||
|
if Input.getKeyDown(Input.KeyCode.Down) then
|
||||||
|
pos = pos - helper.forward * this.speed
|
||||||
|
end
|
||||||
|
if Input.getKeyDown(Input.KeyCode.Right) then
|
||||||
|
pos = pos + helper.right * this.speed
|
||||||
|
end
|
||||||
|
if Input.getKeyDown(Input.KeyCode.Left) then
|
||||||
|
pos = pos - helper.right * this.speed
|
||||||
|
end
|
||||||
|
|
||||||
|
local mb0 = Input.getMouseButtonJustPressed(0)
|
||||||
|
local mb1 = Input.getMouseButtonJustPressed(1)
|
||||||
|
local mb2 = Input.getMouseButtonJustPressed(2)
|
||||||
|
|
||||||
|
if mb0 or mb1 then
|
||||||
|
hit = rayCast(this.worldPosition, helper.forward, 300)
|
||||||
|
if(hit.hasHit) then
|
||||||
|
local hitForce = 1000
|
||||||
|
rb = hit.object:getComponent(Rigidbody)
|
||||||
|
if mb0 then
|
||||||
|
rb:addForce(hit.hitNormal * -hitForce)
|
||||||
|
elseif mb1 then
|
||||||
|
rb:addForce(hit.hitNormal * hitForce)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if mb2 then
|
||||||
|
this.toggleCursor()
|
||||||
|
end
|
||||||
|
|
||||||
|
this.position = pos
|
||||||
|
end
|
||||||
|
|
||||||
10
res/project/res/scripts/TestScene/CameraHelper.lua
Normal file
10
res/project/res/scripts/TestScene/CameraHelper.lua
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
this.on_init = function()
|
||||||
|
this.angles = Vec3:new()
|
||||||
|
this.mouse_sens = 0.01
|
||||||
|
end
|
||||||
|
|
||||||
|
this.on_update = function()
|
||||||
|
local deltaMouseMovement = Input.getDeltaMousePos()
|
||||||
|
this.angles.x = this.angles.x - deltaMouseMovement.y * this.mouse_sens
|
||||||
|
this.eulerAngles = this.angles
|
||||||
|
end
|
||||||
14
res/project/res/scripts/TestScene/Child.lua
Normal file
14
res/project/res/scripts/TestScene/Child.lua
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
this.on_init = function ()
|
||||||
|
this.custom_eulerangles = Vec3:new()
|
||||||
|
this.custom_angularvelocity = Vec3:new(0, 0.01, 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
this.on_fixedupdate = function ()
|
||||||
|
if Input.getKeyDown(Input.KeyCode.Left) then
|
||||||
|
this.custom_eulerangles:add(Vec3:new(0,0.01,0))
|
||||||
|
end
|
||||||
|
if Input.getKeyDown(Input.KeyCode.Right) then
|
||||||
|
this.custom_eulerangles:sub(Vec3:new(0,0.01,0))
|
||||||
|
end
|
||||||
|
this.eulerAngles = this.custom_eulerangles
|
||||||
|
end
|
||||||
22
res/project/res/scripts/TestScene/Player.lua
Normal file
22
res/project/res/scripts/TestScene/Player.lua
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
-- this.on_collisionenter = function(other)
|
||||||
|
-- other.position = other.position + Vec3:new(3.2, 0, 0)
|
||||||
|
-- end
|
||||||
|
|
||||||
|
this.on_update = function ()
|
||||||
|
rb = this:getComponent(Rigidbody)
|
||||||
|
if Input.getKeyDown(Input.KeyCode.Space) then
|
||||||
|
rb:addForce(Vec3:new(0, 100, 0))
|
||||||
|
end
|
||||||
|
if Input.getKeyDown(Input.KeyCode.D) then
|
||||||
|
rb:addForce(Vec3:new(10, 0, 0))
|
||||||
|
end
|
||||||
|
if Input.getKeyDown(Input.KeyCode.A) then
|
||||||
|
rb:addForce(Vec3:new(-10, 0, 0))
|
||||||
|
end
|
||||||
|
if Input.getKeyDown(Input.KeyCode.W) then
|
||||||
|
rb:addForce(Vec3:new(0, 0, -10))
|
||||||
|
end
|
||||||
|
if Input.getKeyDown(Input.KeyCode.S) then
|
||||||
|
rb:addForce(Vec3:new(0, 0, 10))
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user