Multiple Demo Changes

Signed-off-by: Robear Selwans <robear.selwans@outlook.com>
This commit is contained in:
2021-07-25 10:48:35 +02:00
parent f9018c9878
commit 7e25e7198d
13 changed files with 1009 additions and 33 deletions
+1 -8
View File
@@ -1,5 +1,5 @@
this.on_init = function()
this.speed = 0.01
this.speed = 0.1
this.angles = Vec3:new()
this.mouse_sens = 0.01
end
@@ -33,12 +33,5 @@ this.on_update = function()
pos = pos - helper.right * this.speed
end
if Input.getMouseButtonJustPressed(0) then
hit = rayCast(this.worldPosition, helper.forward, 300)
if(hit.hasHit) then
hit.object.position = hit.object.position + Vec3:new(0, 0, -15)
end
end
this.position = pos
end
+12 -1
View File
@@ -3,9 +3,20 @@ this.on_init = function()
this.mouse_sens = 0.01
end
function clamp(min, max, val)
if val < min then
return min
elseif val > max then
return max
else
return val
end
end
this.on_update = function()
local deltaMouseMovement = Input.getDeltaMousePos()
this.angles.x = this.angles.x - deltaMouseMovement.y * this.mouse_sens
this.angles.x = clamp(-1.57, 1.57, this.angles.x - deltaMouseMovement.y * this.mouse_sens)
print(this.angles.x)
this.eulerAngles = this.angles
if Input.getKeyJustPressed(Input.KeyCode.O) then
+50
View File
@@ -0,0 +1,50 @@
-- Parameters
this.held = nil
this.held_distance = 0
this.rigidness = 0.2
this.distance_change_speed = 0.1
this.speed_factor = 5.0
-- this.on_init = function()
-- end
this.vec_mag = function(v)
return (v.x^2 + v.y^2 + v.z^2) ^0.5
end
this.vec_lerp = function(v1,v2,t)
return v1 * (1-t) + v2 * (t)
end
this.check_inputs = function()
if Input.getMouseButtonJustPressed(0) then
hit = rayCast(this.worldPosition, this.forward, 3000)
if(hit.hasHit) then
this.held = hit.object
this.held_distance = this.vec_mag(hit.object.worldPosition - this.worldPosition)
end
end
if Input.getMouseButtonJustReleased(0) then
this.held = nil
end
if Input.getMouseButtonDown(3) then
this.held_distance = this.held_distance + this.distance_change_speed
end
if Input.getMouseButtonDown(4) then
this.held_distance = this.held_distance - this.distance_change_speed
end
end
this.on_update = function()
this.check_inputs()
if this.held then
target_position = this.worldPosition + this.forward * this.held_distance
-- this.held.position = this.vec_lerp(this.held.position, target_position, this.rigidness)
rb = this.held:getComponent(Rigidbody)
rb:setVelocity((target_position - this.held.worldPosition) * this.speed_factor)
end
end
+11
View File
@@ -0,0 +1,11 @@
this.shootForce = 600
this.on_update = function()
if Input.getKeyJustPressed(Input.KeyCode.P) then
spawn = loadPrefab('prefabs://DamagedHelmet.pf')
spawn.position = this.worldPosition
rb = spawn:getComponent(Rigidbody)
rb:addForce(Vec3:new(-1, -2, 1) * this.shootForce)
end
end
+3
View File
@@ -0,0 +1,3 @@
this.on_collisionenter = function(other)
destroyObject(other)
end