Blendman,
Here is my personal code for my doors.
How the doors opens depends on how my character moves in. But its always on the same side of the object to give realism.
function door_plyr_maintenance()
for i = 0 to area_doors.length
dist_x# = abs( GetObjectX(game.player.objID) - GetObjectX( area_doors[i].ID ) )
dist_z# = abs( GetObjectZ(game.player.objID) - GetObjectZ( area_doors[i].ID ) )
print( dist_x# )
print( dist_z# )
if dist_x# < .51 and dist_z# < .51 and area_doors[i].open = 0 // this is very sensitive because I move my doors based off angle. My offset is the center and not the left side. If agk was //"better" with 3d animations I would have made an animated door. I encourage you to take this route
open_door( i ) // character controller
continue
elseif dist_x# > 1.10001 and area_doors[i].open = 1 or dist_z# > 1.10001 and area_doors[i].open = 1 // slightly arbitrary but if its close to the open_door test you will have constant //opening and closing
close_door( i ) // character controller
endif
next i
endfunction
function open_door( i as integer )
doorID = area_doors[i].id
dir_x# = GetObjectX( doorID ) - GetObjectX( game.player.objID )
dir_z# = GetObjectZ( doorID ) - GetObjectZ( game.player.objID )
dr_angle# = GetObjectAngleY( doorID )
if dir_z# < 0 and round(dr_angle#) = 0 // players is headed south
SetObjectPosition( doorID, GetObjectX( doorID )-.5, GetObjectY( doorID ), GetObjectZ( doorID )-.3 )
SetObjectRotation( doorID, 0, 125, 0 )
area_doors[i].open = 1
endif
if dir_z# > 0 and round(dr_angle#) = 0 //player is headed north
SetObjectPosition( doorID, GetObjectX( doorID )-.5, GetObjectY( doorID ), GetObjectZ( doorID )+.3 )
SetObjectRotation( doorID, 0, 240, 0 )
area_doors[i].open = 1
endif
if dir_x# > 0 and round(dr_angle#) = 90// player headed east
SetObjectPosition( doorID, GetObjectX( doorID )+.3, GetObjectY( doorID ), GetObjectZ( doorID )-.5 )
SetObjectRotation( doorID, 0, 215, 0 )
area_doors[i].open = 1
endif
if dir_x# < 0 and round(dr_angle#) = 90 // player headed west
SetObjectPosition( doorID, GetObjectX( doorID )-.3, GetObjectY( doorID ), GetObjectZ( doorID )-.5 )
SetObjectRotation( doorID, 0, 325, 0 )
area_doors[i].open = 1
endif
endfunction
function close_door( i as integer )
doorID = area_doors[i].id
dr_angle# = GetObjectAngleY( doorID )
if round(dr_angle#) = 125 or round(dr_angle#) = 240
SetObjectRotation( doorid, 0, 0, 0 )
area_doors[i].open = 0
elseif round(dr_angle#) = 215 or round(dr_angle#) = 325
SetObjectRotation( doorid, 0, 90, 0 )
area_doors[i].open = 0
endif
i = search_for_door_id( doorid )
obj = house_construction[i].ID
SetObjectPosition( doorid, GetObjectX( obj ), GetObjectY( obj ), GetObjectZ( obj ) )
endfunction