# How do I make a kinematic object (player) push a dynamic object?

**URL:** <https://forum.defold.com/t/how-do-i-make-a-kinematic-object-player-push-a-dynamic-object/67565>\
**Category:** Questions\
**Created:** [February 15, 2021, 3:46am UTC](https://forum.defold.com/t/how-do-i-make-a-kinematic-object-player-push-a-dynamic-object/67565 "2021-02-15T03:46:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abhishek](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/abhishek/32/23477_2.png) [@Abhishek](https://forum.defold.com/u/Abhishek)\
**Post date:** [February 15, 2021, 3:46am UTC](https://forum.defold.com/t/how-do-i-make-a-kinematic-object-player-push-a-dynamic-object/67565/1 "2021-02-15T03:46:10Z")

</div>

Like I asked, I want the player to be able to push the object, on contact.

My **player.script** :

```
function init(self)
	msg.post(".","acquire_input_focus")
	self.runSpeed = 50
	self.curAnim = "idle"
	msg.post("#idle", "play_animation", { id=hash("idle") })
	self.speed = vmath.vector3()
end

function update(self, dt)
	local pos = go.get_position()
	if self.speed.x ~= 0 then    
		pos = pos + self.speed * dt
		go.set_position(pos)	

		if self.curAnim ~= "run" then
			msg.post("#idle", "play_animation", { id=hash("run") })
			self.curAnim = "run"
		end
	end
end

function on_input(self, action_id, action)
	if action_id == hash("RIGHT") then
		if action.pressed then
			self.speed.x = self.runSpeed
			sprite.set_hflip("#idle", false)
		elseif action.released then
			self.speed.x=0
			msg.post("#idle", "play_animation", { id=hash("idle") })
			self.curAnim = "idle"
			sprite.set_hflip("#idle", false)
		end
	end    
	if action_id == hash("LEFT") then
		if action.pressed then
			self.speed.x = self.runSpeed * -1
			sprite.set_hflip("#idle", true)
		elseif action.released then
			self.speed.x=0
			msg.post("#idle", "play_animation", { id=hash("idle") })
			self.curAnim = "idle"
			sprite.set_hflip("#idle", true)
		end
	end 
end

```

---

<div class="post-metadata">

**Author:** ![SpencerWF](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/spencerwf/32/21158_2.png) [@SpencerWF](https://forum.defold.com/u/SpencerWF)\
**Post date:** [February 15, 2021, 10:24am UTC](https://forum.defold.com/t/how-do-i-make-a-kinematic-object-player-push-a-dynamic-object/67565/2 "2021-02-15T10:24:24Z")

</div>

Depending on what you are after you could do at least 3 ways I can see:

1. Attach the object ‘go’ to your player ‘go’ through [go.set\_parent()](https://defold.com/ref/stable/go/?q=go#go.set_parent:%5Bid%5D-%5Bparent_id%5D-%5Bkeep_world_transform%5D)
2. Make the object into a dynamic object instead of kinematic
3. Implement kinematic collisions as described [here](https://defold.com/manuals/physics-resolving-collisions/)

For solution 1:  
You want some sort of ‘grab’ mechanic, the player can grab and drop the object, and in so doing you will add or remove the player as the parent of the game object. Make sure when the player releases the object to assign the right new parent.

For solution 2:  
Let the physics engine handle your collisions, and you can just edit the traits of the object and player.

For solution 3:  
Make sure to read the whole page I linked, it goes through handling collisions with kinematic objects well, but to make sure that it handles well will require that you do implement what is described there.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [February 15, 2021, 10:37am UTC](https://forum.defold.com/t/how-do-i-make-a-kinematic-object-player-push-a-dynamic-object/67565/3 "2021-02-15T10:37:45Z")

</div>

> [@Abhishek](#):
>
> Like I asked, I want the player to be able to push the object, on contact.

Did you see this post with three different options to achieve what you wanted, complete with a demo project?

> [@How do I add a dynamic collision box on my player?](https://forum.defold.com/t/how-do-i-add-a-dynamic-collision-box-on-my-player/67550/3):
>
> Kinematic bodies should still collide with dynamic ones if the mask matches. The simulation might be unpredictable, though, because kinematic bodies are moved with set\_position(). In your example above you should be ok I think, because the movement is so slow. You can also set linear velocity on a kinematic body. Although this won’t make it move (like in vanilla Box2D) dynamic bodies react like it does if linear velocity is set. This helps interaction with dynamic bodies. Update: Push a box, t…
