Hey,
yesterday i wrote a simple door code that worked perfectly.
but when adding DP to it things stopped working again.
this is my door:
this is my DBPRO Code:
Loading Level:
` MAKE DOOR
if family$ = "door"
Clone Object id, TEMP_OBJECT_DOOR : Show Object id
set shadow shading on id, -1, 1000, 1
Phy Make Rigid Body Static Box id
endif
` UPDATE OBJECTS
if family$ <> "light"
Position Object id, posx, posy, posz
Rotate Object id, wrapvalue(angx), wrapvalue(angy), wrapvalue(angz)
If family$ = "door"
Phy Set Rigid Body Position id, posx, posy, posz
Phy Set Rigid Body Rotation id, wrapvalue(angx), wrapvalue(angy), wrapvalue(angz)
fix object pivot id
EndIf
ELSE
This is the DOOR code:
Function doors()
Local CameraX AS Float
Local CameraY AS Float
Local CameraZ AS Float
CameraX = Camera Position X()
CameraY = Camera Position Y()
CameraZ = Camera Position Z()
For c = 1 to totalObjects
If Entity(c).Family = "door"
distance# = SQRT( (CameraX - Entity(c).Position.X)^2 + (CameraY - Entity(c).Position.Y)^2 + (CameraZ - Entity(c).Position.Z)^2 )
If distance# < 200
If Pick Object( screen width()/2, screen height()/2, 1, totalObjects ) = c
If scancode()=18 ` E
If dooropen(c)=0 Then opendoor( c ) Else closedoor(c)
EndIf
EndIf
EndIf
doorupdate(c)
EndIf
Next c
EndFunction
Function opendoor( c )
Entity( c ).Door.Action = "open"
EndFunction
Function closedoor( c )
Entity( c ).Door.Action = "close"
EndFunction
Function dooropen( c )
state = Entity( c ).Door.State
EndFunction state
Function doorupdate( c )
If Entity( c ).Door.Action = "open"
if Entity(c).Door.Stage = 0
Entity(c).Door.NewAngle = 0
Entity(c).Door.Stage = 1
Position Sound DOOR_OPEN_DOOR, Entity(c).Position.X, Entity(c).Position.Y, Entity(c).Position.Z
Play Sound DOOR_OPEN_DOOR
endif
if Entity(c).Door.Stage = 1
Entity(c).Door.NewAngle = wrapvalue( Entity(c).Door.NewAngle + 1 )
If Entity(c).Door.NewAngle >= 90
Entity( c ).Door.Action = "idle" : Entity( c ).Door.State = 1 : Entity(c).Door.Stage = 0
EndIf
`yRotate Object c, Entity(c).Door.NewAngle
Phy Set Rigid Body Rotation c, Object Angle X(c), Entity(c).Door.NewAngle, Object Angle Z(c)
endif
EndIf
If Entity( c ).Door.Action = "close"
if Entity(c).Door.Stage = 0
Entity(c).Door.NewAngle = 90
Entity(c).Door.Stage = 1
endif
if Entity(c).Door.Stage = 1
Entity(c).Door.NewAngle = wrapvalue( Entity(c).Door.NewAngle - 1 )
If Entity(c).Door.NewAngle <= 0
Entity( c ).Door.Action = "idle" : Entity( c ).Door.State = 0 : Entity(c).Door.Stage = 0
EndIf
`yRotate Object c, Entity(c).Door.NewAngle
Phy Set Rigid Body Rotation c, Object Angle X(c), Entity(c).Door.NewAngle, Object Angle Z(c)
endif
EndIf
EndFunction
if i remove the DP code, it works perfect as i just said.
but when the dp code is implemented, some doors don't open and other doors rotate 180 degrees then stop (not increased by 1 as it should be, but increased by 180 each step).
so, anyone know what is wrong with this?