|Category||Farming Simulator 2009|
|Christer F (unknown)||30.05.2010 15:23|
I'm new to modding with the Giants engine. I'm trying to modify a script so when objects hit a shape a trigger callback event should occur. Its a small square bale trailer, should be self loading (the script I'm editing can load if one presses a keyboard button).
Is this even possible? In the script documentation it says only static and kinematic rigid bodies can act as triggers. But a trailer's rigid body parts are dynamic. Does it mean that a trigger shape couldn't be "attached" to it and follow it around the field, it can just be stationary or go on predefined paths (train-like)?
So what I've tested thus far:
Using blender I created a simple cube shape and exported it to i3d. Imported with the giants editor into the i3d of the trailer. A tried both having it as a separate shape and (by editing the i3d file) moved it into a subshape of one of the shapes of the trailer. I made it (the cube) rigid, tried both with static and kinematic. Of course trigger checkbox was checked. I made it non rendable (like the triggers on the straw elevator). I have tried with collision mask of "ff" (standard) and "1000" (the one used by the elevatorMoverTrigger for the strawElevator.
All good so far?
I put the addTrigger call in the script loading function "load(xmlFile)" in the script and after that I tried to have it in the function where one normally triggers the loading of bales ("on-off switch" idea). Is it somewhere else it should be put?
The call was this:
addTrigger(214, "triggerCallback", self);
Where 214 is the ID shown in giants editor, just under the name in the attributes window, as I was just testing I didn't care to have the id number stored in the XML file and loading it, I just put it statically there. Wrong turn in doing that?
"triggerCallback" is the name of a member function I wrote class/table (whatever it should be called in lua) in the lua script, like:
function myclass:triggerCallback(triggerId, otherId, onEnter, onLeave, onStay)
In that function I had just called the bale loading function.
Right now I have a dirty solution, that every 100th time the draw function is called it calls the bale loading function. It will look nicer if I can get the bales to be "catched" in the right moment as they hit the trailer.
Thanks in Advance!
|Bartosz Koperski (unknown)||31.05.2010 21:16|
|Try to put addTrigger in update(dt) function.
I think you should also replace trigger ID ("214") with float. Add new xml line, eg. <trigger id="X" /> (where X is trigger index, eg. 1|0|5) and then create float in load(xmlFile) function self.trigger = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.trigger#id"))
Then just replace 214 with self.trigger
I'm not good at LUA but it should work.
"It will look nicer if I can get the bales to be "catched" in the right moment as they hit the trailer."
If you want to call function when contact occurs, try "addContactReport" (You'll find it in Scripting Reference).
|Christer F (unknown)||31.05.2010 22:43|
|Do you mean that the addTrigger function needs to be called for every single frame (that's when update is called) to keep it?
"replace trigger ID ("214") with float"? You don't mean a floating point value (as the argument should be integer). But the way you describe it, I've seen it and now understood it. It's possible that Utils.indexToObject returns a different number at runtime than whats in the editor. I Will try it with that "path" thing (e.g. 1|5|4).
Thanks about the contact report. I've read up on it and think it is not the best thing. Then the bales have to fall through the others and hit the bottom of the trailer before being detected. I think an invisible, non-collisionable mesh will be best placed in the upper front of the trailer. As I understod that, when things get the trigger attribute they stop offering collision to others.
|Bartosz Koperski (unknown)||01.06.2010 22:42|
|"Do you mean that the addTrigger function needs to be called for every single frame (that's when update is called) to keep it?"
I'm not sure, but I think if you put addTrigger in load(xmlFile) it looks for objects inside trigger only when script is loaded, and to keep it you should put it in update(dt) function.
"ou don't mean a floating point value"
Yeah, my mistake. I wanted to say 'variable', not 'float'.
|Benjamin G (unknown)||16.06.2010 08:34|
|the ID 214 in GE IS NOT the ID inGame! but you can work with a scriptCallback in the Userattributes
Note: Log in to post. Create a new account here.