Skip to content

Commit abe701d

Browse files
committed
added recoil script example
1 parent 82e342d commit abe701d

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

examples/Recoil.lua

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--[[
2+
This tutorial explains how to use the BulletInit
3+
callback to make a weapon have recoil
4+
5+
By VTrider
6+
--]]
7+
8+
local function DoRecoil(odf, shooter, transform)
9+
if odf ~= "blast" then return end
10+
local front = SetVector(transform.front_x, transform.front_y, transform.front_z)
11+
local recoilDirection = -(Normalize(front))
12+
local recoilAmount = 10.0 -- m/s
13+
14+
-- Do a constant recoil impulse
15+
local shooterCurrentVeloc = GetVelocity(shooter)
16+
SetVelocity(shooter, shooterCurrentVeloc + recoilDirection * recoilAmount)
17+
18+
-- Shake the shooter too!
19+
local currentOmega = GetOmega(shooter)
20+
-- x = pitch shake, y = yaw shake, z = roll shake
21+
SetOmega(shooter, SetVector(math.random(5, 15) * 0.1, math.random(-25, 25) * 0.01, currentOmega.z))
22+
end
23+
24+
function exu.BulletInit(odf, shooter, transform)
25+
DoRecoil(odf, shooter, transform)
26+
end

0 commit comments

Comments
 (0)