Cant get physics to collide

Yes! That was it… Why was that even set to true?

Also, just as a quick question, how do I alter the physics to feel more “real”? I want to made the box heavier, so it falls down quicker. I got some really nice looking results by setting the gravity to 50, but that feels like a cheap way of doing it. Plus, it makes the collisions have less “oomph” [import]uid: 200198 topic_id: 36150 reply_id: 143585[/import]

Yeah it is strange that it was set up that way, I guess no one noticed before as there’s nothing for it to collide with in the demo.

Increasing the density value will make it heavier and therefore fall quicker. It’s a careful balancing act to get all your objects interacting with both each other and gravity how you want them to. Remember if you make something more dense you will need to apply more force initially to send it flying at the same speed. [import]uid: 93133 topic_id: 36150 reply_id: 143588[/import]

So I was right… The weird thing is, altering the density of the crate doesn’t seem to affect it in the slightest. Density=2 and density=500 yields the same slow feather-like fall. It does affect how the bullet hits it though, lower densities make it fly further (and easier) than higher densities.

And another question, something that I thought would be easier, but is apparently more difficult than I thought. How do I run code on collision? For example, I want to print something when the bullet hits the crate.

I tried using the example code from the Detect Collisions code

[code]local function onLocalCollision( self, event )
if ( event.phase == “began” ) then

print( self.myName … ": collision began with " … event.other.myName )

elseif ( event.phase == “ended” ) then

print( self.myName … ": collision ended with " … event.other.myName )

end
end

projectiles_container.collision = onLocalCollision
projectiles_container:addEventListener( “collision”, projectiles_container )[/code]

But I’m not quite sure how to call the bullet. But I dont think projectiles_container is the one I need to call. Nor am I quite sure where to put this code. [import]uid: 200198 topic_id: 36150 reply_id: 143592[/import]

Managed to solve it!

And it was as simple as I thought.

[code]-- Check if it hits something
local function checkCollision(event)
if event.phase == “began” then
print( “Hey, I hit something!” )
end
end

t:addEventListener( “collision”, checkCollision )[/code]

Add that after Launch Projectile code and it works like a charm. [import]uid: 200198 topic_id: 36150 reply_id: 143609[/import]

Hi there,

On your other question about how to make objects fall faster, altering their densities won’t help, since all objects accelerate at the same rate regardless of their mass (true in the real world, and true in the physics engine!).

Instead, you can do one of two things. First, you can make the force of gravity stronger, which you’ve already tried. Second, you could change the “scale” of the physics engine using [lua]physics.setScale()[/lua]. Setting the scale to a smaller value should make objects appear to fall faster, even with the same gravity. (The analogy in real life is that a 1-foot ball 1 foot above the ground will hit the ground pretty quickly, but a 100-foot ball 100 feet above the ground will take more time to hit the ground.)

Hope this helps!

  • Andrew [import]uid: 109711 topic_id: 36150 reply_id: 143629[/import]