# How to make factory objects collectable?

**URL:** <https://forum.defold.com/t/how-to-make-factory-objects-collectable/1836>\
**Category:** Questions\
**Created:** [May 12, 2016, 10:51am UTC](https://forum.defold.com/t/how-to-make-factory-objects-collectable/1836 "2016-05-12T10:51:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Teymur\_Gasanov](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/t/cc9497/32.png) [@Teymur\_Gasanov](https://forum.defold.com/u/Teymur_Gasanov)\
**Post date:** [May 12, 2016, 10:51am UTC](https://forum.defold.com/t/how-to-make-factory-objects-collectable/1836/1 "2016-05-12T10:51:01Z")

</div>

How can I make factory objects(for example coins) collectable? I tried to find it out in tutorial but I couldn’t. Here is my factory code

```lua
local frequency = 0.8
local black_prob = 0.3
local min_y = 150
local max_y = 650
function init(self)
	self.timer = 1/frequency
end
function update(self, dt)
	self.timer = self.timer - dt
	if self.timer <= 0 then
		self.timer = 1/frequency
		local pos = go.get_position()
		pos.y = math.random(min_y, max_y)
		local spider = "#orange_factory"
		if math.random() < black_prob then
			spider = "#black_factory"
		end
		factory.create(spider,pos)			
	end
end

```

And here is hero code

```lua
local max_height = 670
local min_height = 150
local max_speed = 300
function init(self)
	msg.post(".", "acquire_input_focus")
	self.speed = -200
end
function update(self, dt)
	local pos = go.get_position()
	pos.y = pos.y + self.speed * dt
	if pos.y > max_height then
		pos.y = max_height
	elseif pos.y < min_height then
		pos.y = min_height
	end
	go.set_position(pos)
	self.speed = -200
end
function on_input(self, action_id, action)
    if action_id == hash("up") then
		self.speed = max_speed
		if action.pressed then 
			msg.post(go.get_id(), hash("play_animation"), {id = hash("anim")})
		end
	end
end

```

---

<div class="post-metadata">

**Author:** ![rsletta](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/rsletta/32/707_2.png) [@rsletta](https://forum.defold.com/u/rsletta)\
**Post date:** [May 12, 2016, 11:01am UTC](https://forum.defold.com/t/how-to-make-factory-objects-collectable/1836/2 "2016-05-12T11:01:08Z")

</div>

Add physics trigger on coin. Let the collision with the hero trigger a message to the hero, or a function in the coin script. Then handle as best fit.

---

<div class="post-metadata">

**Author:** ![sicher](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sicher/32/8_2.png) [@sicher](https://forum.defold.com/u/sicher)\
**Post date:** [May 12, 2016, 11:03am UTC](https://forum.defold.com/t/how-to-make-factory-objects-collectable/1836/3 "2016-05-12T11:03:28Z")

</div>

See [Getting started with Defold](http://www.defold.com/tutorials/getting-started/#_step_9_coins_to_collect)
