Skip to content

Commit

Permalink
StackOBot destroy after dying.
Browse files Browse the repository at this point in the history
PhysicsGun offsets third person Camera ArmLength
  • Loading branch information
gtnardy committed Mar 19, 2023
1 parent b128107 commit 99547d5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Client/Tools/PhysicsGun.lua
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ function TryPickUpObject()
-- Calculates the offset of the hit and the center of the object
PhysicsGun.picking_object_relative_location = PhysicsGun.picking_object:GetRotation():RotateVector(PhysicsGun.picking_object:GetLocation() - trace_result.Location)

-- Calculates the distance of the object and the camera
PhysicsGun.picking_object_distance = trace_result.Location:Distance(viewport_3D.Position)
-- Calculates the distance of the object and the camera, adds ArmLength to normalize Camera Views
PhysicsGun.picking_object_distance = trace_result.Location:Distance(viewport_3D.Position) - Client.GetLocalPlayer():GetCameraArmLength()

PhysicsGun.picking_object_initial_rotation = PhysicsGun.picking_object:GetRotation() - Client.GetLocalPlayer():GetControlledCharacter():GetRotation()

Expand Down Expand Up @@ -416,7 +416,7 @@ function PhysicsGunTick()

-- Gets the new object location using some Math, first gets the overall location: start_location + camera_direction * the distance
-- Then adds the offset of the object when it was grabbed, rotating it with the object rotation
local end_location = (start_location + camera_direction * PhysicsGun.picking_object_distance) + PhysicsGun.picking_object:GetRotation():UnrotateVector(PhysicsGun.picking_object_relative_location)
local end_location = (start_location + camera_direction * (PhysicsGun.picking_object_distance + Client.GetLocalPlayer():GetCameraArmLength())) + PhysicsGun.picking_object:GetRotation():UnrotateVector(PhysicsGun.picking_object_relative_location)

-- The new object rotation will be the initial rotation + the camera rotation
local camera_rotation = Client.GetLocalPlayer():GetCameraRotation()
Expand Down
2 changes: 1 addition & 1 deletion Package.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# contributors
author = "nanos™"
# version
version = "3.5.0"
version = "3.5.1"

# game-mode configurations
[game_mode]
Expand Down
7 changes: 7 additions & 0 deletions Server/NPC.lua
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,10 @@ function StackOBot:MoveRandom(distance)
local random_location = self:GetLocation() + Vector(math.random(distance) - distance / 2, math.random(distance) - distance / 2, 0)
self:MoveTo(random_location, 250)
end

-- After dying, destroys the Character after 10 seconds
function StackOBot:OnDeath()
self:SetLifeSpan(10)
end

StackOBot.Subscribe("Death", StackOBot.OnDeath)

0 comments on commit 99547d5

Please sign in to comment.