Better controls
parent
a8cc8c8a1b
commit
7d9337e84b
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
local UFO_SPEED = 1
|
local UFO_SPEED = 10
|
||||||
local UFO_TURN_SPEED = 2
|
local UFO_TURN_SPEED = 2
|
||||||
|
|
||||||
local ufo = {
|
local ufo = {
|
||||||
|
@ -39,22 +39,30 @@ end
|
||||||
function ufo:on_step (dtime)
|
function ufo:on_step (dtime)
|
||||||
if self.driver then
|
if self.driver then
|
||||||
local ctrl = self.driver:get_player_control()
|
local ctrl = self.driver:get_player_control()
|
||||||
local vel = {x=0,y=0,z=0}
|
local vel = self.object:getvelocity()
|
||||||
|
local acc = self.object:getacceleration()
|
||||||
if ctrl.up then
|
if ctrl.up then
|
||||||
vel.x = math.cos(self.object:getyaw()+math.pi/2)*UFO_SPEED
|
vel.x = math.cos(self.object:getyaw()+math.pi/2)*UFO_SPEED
|
||||||
vel.z = math.sin(self.object:getyaw()+math.pi/2)*UFO_SPEED
|
vel.z = math.sin(self.object:getyaw()+math.pi/2)*UFO_SPEED
|
||||||
|
acc.x = vel.x*.25
|
||||||
|
acc.z = vel.z*.25
|
||||||
|
else
|
||||||
|
acc.x = -vel.x/5
|
||||||
|
acc.z = -vel.z/5
|
||||||
end
|
end
|
||||||
if ctrl.down then
|
if ctrl.down then
|
||||||
vel.x = -self.object:getvelocity().x
|
acc.x = -vel.x
|
||||||
vel.z = -self.object:getvelocity().z
|
acc.z = -vel.z
|
||||||
end
|
end
|
||||||
if ctrl.jump then
|
if ctrl.jump then
|
||||||
vel.y = UFO_SPEED
|
vel.y = UFO_SPEED
|
||||||
end
|
elseif ctrl.sneak then
|
||||||
if ctrl.sneak then
|
|
||||||
vel.y = -UFO_SPEED
|
vel.y = -UFO_SPEED
|
||||||
|
else
|
||||||
|
acc.y = -vel.y/2
|
||||||
end
|
end
|
||||||
self.object:setacceleration(vel)
|
self.object:setvelocity(vel)
|
||||||
|
self.object:setacceleration(acc)
|
||||||
if ctrl.left then
|
if ctrl.left then
|
||||||
self.object:setyaw(self.object:getyaw()+math.pi/120*UFO_TURN_SPEED)
|
self.object:setyaw(self.object:getyaw()+math.pi/120*UFO_TURN_SPEED)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue