Working with Lua scripts
I have been fiddeling with some lua scripts trying to understand. Found the following for movement of a object:
I have used the light position for an example of a dildo moving like this (move forward 0.03 from 0 and move - 0.03 passed 0 to the back.
so move + 0.03 from 0 and move -0.03 back from 0 as a callback. 0.03 is the value used to make the movement. 0.05 will give a longer movement.
local script = {}
--SCRIPT BODY - any functions and calculations
--====================================================================================================
--main function that will be used as frame update callback
--id - object id allow access to object storage
--delta - time passed from last frame, i.e frame time
local function update( id, delta )
--here the main script things logic, calculations and so on
local st = db.storage[id]
if st then
st.object.position = st.object.position + Vector3( 0, 0, 1) * st.move_speed * delta Vector3 is the same as (x,y,z) the possition where you set your 1 will be the axis used in the code, this one is Z for backward and forward, Y up and down, x left and right)
if st.object.position.z > (st.base_pos.z + 0.03) or st.object.position.z < (st.base_pos.z - 0.03) then if st.objects.position.z is bigger than st.base_pos.z [so thats 0] or st.object.position.z is smaller than 0
st.move_speed = st.move_speed * -1 This will give the movement
end
end
end
--================================================================================================
--BIND - this function called when object binded with script and allow register all desired callbacks
--================================================================================================
function script:bind_to_object( st, binder )--object storage and callback binder
--declare per object variables
st.base_pos = st.object.position this sets the =0.03 and -0.03
st.move_speed = 0.8 set the speed of the toy here where 1 is max
--register callback in array of active callbacks this will make it repeat
binder:add_callback( CALLBACK_GLOBAL, "on_frame_update", st.object.id, update )
--callback class
--callback type
--object id
--function that will be used as callback
end
--====================================================================================================
--script registration
db.script_list["sc_simple_light_position_move"] = script this is where you name the script. needs to be the same as script name
i have called it simple_move_position.script
1. so set your axis here by placing the 1 to vector3 st.object.position = st.object.position + Vector3( 0, 0, 1) read as (x,y,z) or (left\right, up\down, forward\backward)
2. set your movement coordinates here if st.object.position.z > (st.base_pos.z + 0.03) or st.object.position.z < (st.base_pos.z - 0.03) then
3. set your speed here st.move_speed = 0.8 where 1 is max
set the object in your leveldef like this:
[Dildo script]
enable = true
type = static
style = object
file = ![obj] h5 sexvision obj pack\cockpack\youthcockpack1\youthcockalienengineer\meshes0.h5m
position = 0.850370, 1.677861, -0.644488
rotation = 0.000000, 0.000000, 0.000000
scale = 1.000000, 1.000000, 1.000000
color_multiplier = 255, 255, 255, 255
metallness_multiplier = 1.000000
glosiness_multiplier = 1.000000
glow_intensity = 0.000000
cast_shadow = true
alpha_mask = true
alpha_blend = true
cull_mode = 4
rendering_source =
rendering_source_uvoffset = 0.000000, 0.000000
rendering_source_uvscale = 1.000000, 1.000000
script_name = sc_simple_position_move
parent_name =
you can parent a light to the object that used the script to make the light move
add to
[Light}
parent_name = Dildo script
-
2
-
3
2 Comments
Recommended Comments