Hello,
Toxiccloud posted this comment :
Quote: "
Not sure if this belongs here or not but noticed that if you add the spin behavior or the hover behavior to an object, the object loses all collision. this happens no matter what collision settings you use. I imagine it's probably the same for other behaviors as well, but only tried the spin and hover behaviors trying to make moving platforms. Maybe this is a bug, maybe not, perhaps it's just not fully implemented yet. Just wanted to see if anyone has any thoughts or more information.
"
It is not too difficult to modify the behavior "hover.lua" which contains a nice trigonometric formula to create that back-and-forth motion on the vertical axis.
If you examine that behavior you can see that "Collision" and "Gravity" are disabled in the "function init" section of its script.
To convert that behavior into a new one being able to control a moving platform it just takes a few minutes.
Here is a modified version of that behavior ( it is just an idea and it could surely be improved) :
-- DESCRIPTION: The object will hover up and down it`s Y axis by [HOVERHEIGHT=20(1,100)] units.
g_hover_heightangle = {}
g_hover = {}
function hover_properties(e,hoverheight)
g_hover[e]['hoverheight'] = hoverheight
end
function hover_init(e)
g_hover[e] = {}
g_hover[e]['hoverheight'] = 20
--CollisionOff(e)
--GravityOff(e)
g_hover_heightangle[e] = 0
end
function hover_main(e)
CollisionOff(e)
GravityOff(e)
local nhoverheight = g_hover[e]['hoverheight']
g_hover_heightangle[e] = g_hover_heightangle[e] + (GetAnimationSpeed(e)/20.0)
local fFinalY = GetGroundHeight(g_Entity[e]['x'],g_Entity[e]['z']) + nhoverheight + (math.cos(g_hover_heightangle[e])*nhoverheight*10)
SetPosition(e,g_Entity[e]['x'],fFinalY,g_Entity[e]['z'])
CollisionOn(e)
GravityOn(e)
end
What was modified ?
The deactivation of the "Collision" and of the "Gravity" are inserted in the "function main" section of the script before the lines of code controlling the vertical motion.
After the execution of the motion ( I think that this process could be evaluated in microseconds) the "Collision" and the "Gravity" are reactivated.
In this way the player or any object having its "Physics on" parameter enabled will collide in real time with the object to which that modified "hover" behavior is applied.
In that modified version of the script I also changed the speed and height of the motion ( done fast, it is just to give an idea that could inspire you for a better script).
That modified behavior was successfully tested on an object (an imported mesh) for which I forced the combination "Physics on" with Collision Shape "Polygon" (*) to transform it into a moving platform/elevator.
(*) Surprisingly it is possible to cheat with the settings in the parameters of the "Object Tools".