Kinematic Bodies Won't Spin

So I am trying to get kinematic bodies to shoot forward and spin. Think throwing ninja stars but no matter how many angular and rotation functions I use, I see no difference.
Is this a bug or am I just missing something huge?
[lua]local vBot = Primate:new(“caveman”)
physicsGroup:insert(vBot)
vBot:translate(x, y + spacing)
vBot.xScale, vBot.yScale = xScale, yScale
physics.addBody(vBot, vBot.physics)
vBot.bodyType = “kinematic”

local vTop = Primate:new(“caveman”)
physicsGroup:insert(vTop)
vTop:translate(x, y - spacing)
vTop.xScale, vTop.yScale = xScale, yScale
physics.addBody(vTop, vTop.physics)
vTop.bodyType = “kinematic”

–shoot forward
vBot:setLinearVelocity(500, 0)
vTop:setLinearVelocity(500, 0)
–spin
vBot.isFixedRotation = false
vTop.isFixedRotation = false
primate:applyAngularImpulse(50)
vBot:applyAngularImpulse(50)
vTop:applyAngularImpulse(50)
primate:applyTorque(50)
vBot:applyTorque(50)
vTop:applyTorque(50)[/lua] [import]uid: 54716 topic_id: 20963 reply_id: 320963[/import]

Do your objects have friction? If not thats probably your issue [import]uid: 84637 topic_id: 20963 reply_id: 82805[/import]

They do but they are in midair and the do move with the linearVelocity applied. [import]uid: 54716 topic_id: 20963 reply_id: 82823[/import]

Hey I am also having problems getting the same kinematic bodies to collide with other bodies.

I also removed the changing of the body types(default is dynamic) and the rotation worked perfectly fine. [import]uid: 54716 topic_id: 20963 reply_id: 82827[/import]

Danny any word on this? [import]uid: 54716 topic_id: 20963 reply_id: 83034[/import]

Is this a bug or not? [import]uid: 54716 topic_id: 20963 reply_id: 83170[/import]

If you strip this down to a test case and post it up (just use new rects instead of images) and it still happens i will test it and if a solution cannot be found then it could be a bug [import]uid: 84637 topic_id: 20963 reply_id: 83174[/import]

So the main problems are that I can’t get kinematic and static sensors to collide, and I cannot get kinematic bodies to rotate with body:applyTorque or body:applyAngularImpulse. Now writing this code I realized that even the dynamic body won’t spin… I am using build 704.
[lua]function main()
local physics = require(“physics”)
physics.start()
physics.setScale( 60 )
physics.setPositionIterations( 30 )
physics.setVelocityIterations( 10 )
–items
local rect = display.newRect(0, 0, 50, 50)
local circle = display.newCircle(0, 0, 50)
–pos
rect:translate(60, 180)
circle:translate(360, 180)
–physics
physics.addBody(rect)
physics.addBody(circle)
–bodies
circle.bodyType = “static”
circle.isSensor = true
function circle:collision( event )
print(“Colliding with a Rect”)
circle:setFillColor(0, 200, 50)
event.other:setFillColor(0, 200, 50)
end
circle:addEventListener(“collision”, circle)
rect.bodyType = “kinematic”
–force
rect:setLinearVelocity(50,0)
rect:applyTorque(500)–not working
rect:applyAngularImpulse(500)–not working

–show code works with like bodies
local function delay()
local work = display.newRect(0, 0, 50, 50)
work:translate(60, 180)
physics.addBody(work)
work:setLinearVelocity(1000, 0)
work:applyTorque(500)–weird this is not working either
work:applyAngularImpulse(500)–not working
end
timer.performWithDelay(8000, delay)
end
main()[/lua] [import]uid: 54716 topic_id: 20963 reply_id: 83194[/import]

Thanks for the example case.

Il test this out and work out what is going on. :slight_smile: [import]uid: 84637 topic_id: 20963 reply_id: 83196[/import]

Ok, so there is definately something weird about your set up.

Anyway. here is a working example :

[code]
local physics = require(“physics”)
physics.start()
physics.setGravity(0, 0)

–Create a rectangle
local myRect = display.newRect(150, 100, 100, 100)

–Add a body to the rectangle
physics.addBody(myRect, “kinemetic”, {isSensor = true})

–Set the rectangle’s angular velocity
–myRect.angularVelocity = 50

–or
myRect:applyTorque(10)
[/code] [import]uid: 84637 topic_id: 20963 reply_id: 83330[/import]

But that is not what I need to do. I need gravity. I need linear velocity. I need torque. I need kinematic and dynamic bodies to collide.

There is nothing weird about my set up. Please acknowledge that there is a problem with kinematic bodies not colliding with sensors. Not being able to spin the bodies can be solved with transitions but bodies not colliding is a huge problem that cannot be side stepped.

Apply torque is still not working, but angularVelocity does. The kinematic and dynamic bodies will still not collide. If it a problem with the build, then refer me to a working build.
[lua]function main()
local physics = require(“physics”)
physics.start()
physics.setScale( 60 )
physics.setPositionIterations( 30 )
physics.setVelocityIterations( 10 )
–items
local rect = display.newRect(0, 0, 50, 50)
local circle = display.newCircle(0, 0, 50)
–pos
rect:translate(60, 180)
circle:translate(360, 180)
–physics
physics.addBody(rect)
physics.addBody(circle)
–bodies
circle.bodyType = “static”
circle.isSensor = true
function circle:collision( event )
print(“Colliding with a Rect”)
circle:setFillColor(0, 200, 50)
event.other:setFillColor(0, 200, 50)
end
circle:addEventListener(“collision”, circle)
rect.bodyType = “kinematic”
–rect.isSensor = true
–force
rect:setLinearVelocity(50,0)
–rect:applyTorque(500)–THIS DOES NOT WORK
rect.angularVelocity = 500–THIS WORKS

–show code works with like bodies
local function delay()
local work = display.newRect(0, 0, 50, 50)
work:translate(60, 180)
physics.addBody(work)
work:setLinearVelocity(1000, 0)
–work:applyTorque(500)–THIS DOES NOT WORK
work.angularVelocity = 500–THIS WORKS
end
timer.performWithDelay(8000, delay)
end
main()[/lua] [import]uid: 54716 topic_id: 20963 reply_id: 83392[/import]

There is no need to take that attitude towards me. I am trying to help. I was merely showing that apply torque does indeed work. If that sample I provided does not work for you then there must be something wrong with your corona installation. I tested it and it does work.

When I said weird with your set up i wasn’t been condescending or insulting, was just making a general comment, please don’t take things the wrong way.

Kinematic sensors do collide with dynamic sensors.
Note : In your samples your setting the circle to static and your complaint is that kinematic bodies aren’t colliding with dynamic bodies, you aren’t using a dynamic body
[import]uid: 84637 topic_id: 20963 reply_id: 83394[/import]

I will rewrite the sample code. I am having problems with kinematic and dynamic bodies in my main code, but now I guess static bodies as well. I will update corona. [import]uid: 54716 topic_id: 20963 reply_id: 83396[/import]

I’m having trouble with kinematic objects too. They don’t seem to work as advertised…

Danny, your code only “works” because you spelled “kinematic” wrong. Therefore, your object is actually defaulting to dynamic.

Kinematic objects are, as far as the documents on the Corona site say, only supposed to disregard gravity. They should respond to other forces though. Here’s a super, dead-simple example of that not working.

All I want is a block that will bounce between the side walls while everything else in the environment falls prey to gravity. It doesn’t work:

[code]
local physics = require(“physics”)
physics.start()

local myRect = display.newRect(100, 100, 100, 100)
myRect:setFillColor(80, 40, 40, 255)

–Create a walls
local wall1 = display.newRect(0, 0, 20, 800)
local wall2 = display.newRect(300, 0, 20, 800)
physics.addBody(wall1, “static”)
physics.addBody(wall2, “static”)

physics.addBody(myRect, “kinematic”)

– uncomment these to see how it SHOULD work, but with gravity on
– physics.addBody(myRect, “dynamic”)
– physics.setGravity(0, 0)
myRect:applyForce(10,0, 150, 150)
[/code] [import]uid: 122333 topic_id: 20963 reply_id: 83464[/import]

A kinematic body moves under simulation according to its velocity. Kinematic bodies do not respond to forces. They can be moved manually by the user, but normally a kinematic body is moved by setting its velocity. A kinematic body behaves as if it has infinite mass, however, Box2D stores zero for the mass and the inverse mass. Kinematic bodies do not collide with other static or kinematic bodies.
see chapter 7 bodies

http://www.box2d.org/manual.html#_Toc258082971

:slight_smile:
[import]uid: 12482 topic_id: 20963 reply_id: 83468[/import]

Thanks obscurefolkhero and hgvyas123. :slight_smile: That definitely needs to be placed into the docs on bodies. So then how would one go about creating a kinematic-like body that interacts with static bodies and is unaffected by gravity? [import]uid: 54716 topic_id: 20963 reply_id: 83471[/import]

Ah, that makes sense then. I’m new to the box2D stuff.

But, let’s go back to my example. All I want is a box that collides back and forth against the walls without being affected by gravity. How could I do that?

We’ve established that angularVelocity and linearVelocity will work on the object but not forces or torque.

I altered my code (shown below) to use the linear velocity instead of a force. As you can see, the box moves, but it doesn’t collide with the wall and bounce back. At least if it registered the collision, I could control the object myself, but it doesn’t even do that.

I understand that this might not be the way Box2D works, but it seems like a problem someone must have tackled. What do people usually do? On enter frame apply on opposing force equal to gravity to cancel its effect? Make their own fake gravity that they apply to everything except for those that they don’t want to respond to it?

[code]
local physics = require(“physics”)
physics.start()

local myRect = display.newRect(100, 100, 100, 100)
myRect:setFillColor(80, 40, 40, 255)

–Create a walls
local wall1 = display.newRect(0, 0, 20, 800)
local wall2 = display.newRect(300, 0, 20, 800)
physics.addBody(wall1, “static”)
physics.addBody(wall2, “static”)

physics.addBody(myRect, “kinematic”)

– uncomment these to see how it SHOULD work, but with gravity on
– physics.addBody(myRect, “dynamic”)
– physics.setGravity(0, 0)
–myRect:applyForce(10,0, 150, 150)
myRect:setLinearVelocity(50,0)

local function onCollision(self, event)
print(“colliding!”)
if (event.phase == “began” ) then
myRect:setLinearVelocity(10,0)
end
end

myRect.collision = onCollision
myRect:addEventListener(“collision”, myRect)
[/code] [import]uid: 122333 topic_id: 20963 reply_id: 83473[/import]

one more thing as per box2d kinematic and static bodies cant collide with each other above example is perfect too see that

[edit]
what exactly you wanted too do cant understand by reading all of the above post

some suggestion blindly :slight_smile:

are you able to use dynamic body instead of kinematic body with very high lineardamping?

does the normal function to chk position of both objects and see if they are overlapping will be fine?

can you guys consider to setgravity to 0 and all the objects you want which should have gravity can be put in array and manually giving force to them on every enterfrme event will be fine? [import]uid: 12482 topic_id: 20963 reply_id: 83474[/import]