func_physbox and other physics entities
Quote from Fracture on February 15, 2015, 4:34 pmI am attempting to make an object relay and output ONLY when it remains completely motionless, and to revert those outputs when moving. unfortunately the func_physbox entities only allow for the second and not the first. is there a way around this?
I am attempting to make an object relay and output ONLY when it remains completely motionless, and to revert those outputs when moving. unfortunately the func_physbox entities only allow for the second and not the first. is there a way around this?
Quote from Goldenknighttim on February 15, 2015, 6:43 pmHi Fracture,
I'm not sure if there is a way for the physics entity to tell you if it's moving, but if you don't mind some scripting, I would run the outputs through a logic_relay, and run a script to check to see if the origin of the physics object is the same value as it's last tick, where if it is in the same position, enable the relay, and if it isn't in the same position, disable the relay. I wrote one myself that should work if you want to try this method, but I didn't test it so let me know if you use it and it doesn't work. (unless you can fix it yourself)[spoiler]//Assuming that this function is being called once from the physbox or physics object.
//When calling the script, for a perameter, just user "Vector(0,0,0)"
function Checkmovement(last_pos)
{
//finds current position and logic relay to enable/dissable.
local current_pos = self.GetOrigin()
local relay = Entities.FindByName(null,"static_phys_relay")
//If the two positions match, reach out to a logic_relay that has been named "static_phys_relay" and enables if the physics object is static, and dissables it if the physics object is moving.
if (current_pos == last_pos)
{
EntFireByHandle(relay, "Enable", "", 0.0, null, null)
}
else
{
EntFireByHandle(relay, "Disable", "", 0.0, null, null)
}
//Calls the function again on the next tic, change the delay time as necessary.
EntFireByHandle(self, "RunScriptCode", "Checkmovement("+current_pos+")", 0.1, null, null)
}[/spoiler]
Hi Fracture,
I'm not sure if there is a way for the physics entity to tell you if it's moving, but if you don't mind some scripting, I would run the outputs through a logic_relay, and run a script to check to see if the origin of the physics object is the same value as it's last tick, where if it is in the same position, enable the relay, and if it isn't in the same position, disable the relay. I wrote one myself that should work if you want to try this method, but I didn't test it so let me know if you use it and it doesn't work. (unless you can fix it yourself)
Quote from Fracture on February 15, 2015, 6:46 pmi am about as good at scripts as i am at landing shuttles on the moon O_O
i am about as good at scripts as i am at landing shuttles on the moon O_O
Quote from Goldenknighttim on February 15, 2015, 9:23 pmOk, well I debugged the script and utilized it in an instance, so if you still want to use this method, all you would have to do is place the instance and script in the indicated files, and put the instance in your map. Set the Entity Name Fix Up to either 'none' or 'postfix', set the '$PhysicstoTrack' parameter to the name of your physics item. And put an @ before the name of the physics item in both it's actual name, and the parameter so the instance can reference it. Lastly, if you upload it to the workshop, or to TWP, in the final map, pack the script into the map so it will work on other computers.
https://drive.google.com/file/d/0B9wOk5iIMMN_ajZoMXhXeXJoSjg/view?usp=sharing
I tested with a weighted cube, and it worked perfectly. It ignores subtle movements up to 0.1 units every 0.1 seconds. Let me know if that's a problem.
Edit: I forgot to actually say what this does. It's pretty much a relay that is enabled while the physics object(specified in the parameter) is stationary, and is disabled while the object is moving. Send at an input, and then send an output from it, and it will filter the outputs so they only go off while the physics object is not moving
Ok, well I debugged the script and utilized it in an instance, so if you still want to use this method, all you would have to do is place the instance and script in the indicated files, and put the instance in your map. Set the Entity Name Fix Up to either 'none' or 'postfix', set the '$PhysicstoTrack' parameter to the name of your physics item. And put an @ before the name of the physics item in both it's actual name, and the parameter so the instance can reference it. Lastly, if you upload it to the workshop, or to TWP, in the final map, pack the script into the map so it will work on other computers.
https://drive.google.com/file/d/0B9wOk5iIMMN_ajZoMXhXeXJoSjg/view?usp=sharing
I tested with a weighted cube, and it worked perfectly. It ignores subtle movements up to 0.1 units every 0.1 seconds. Let me know if that's a problem.
Edit: I forgot to actually say what this does. It's pretty much a relay that is enabled while the physics object(specified in the parameter) is stationary, and is disabled while the object is moving. Send at an input, and then send an output from it, and it will filter the outputs so they only go off while the physics object is not moving