Demo entry 6714530

lua script for 3D physics attraction

   

Submitted by anonymous on Feb 14, 2018 at 17:40
Language: Lua. Code size: 617 Bytes.

function Node:onTick()
	if (self.active==false) then
		return
	end	
	tm = getUniverse():getTimeline():getTimeElapsedFromLastTick()
	impulsesPerSec = 20
	impulses = tm:toSeconds() * impulsesPerSec
	nodes = {}
	self:getSpace():getChildNodes(nodes)
	for i=1,#nodes do
		rb = nodes[i]:getRigidBody()
		if (rb and nodes[i] ~= self:getParentNode()) then
			dist = (self:getWorldPosition() - nodes[i]:getWorldPosition()):length()
			dir = (self:getWorldPosition() - nodes[i]:getWorldPosition()):getNormalized()
			inv_sq = 1/dist*dist * impulses
			rb:applyCentralImpulse(dir*rb.mass*inv_sq)
		end
	end
end

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).