Ball getting smaller rolling downhill.

I’m very new at this, but have scanned the Forums and I think the answer might be “No” because it can’t be done with a physics item, but here’s the scenario.

I want a rock to roll downhill and get smaller as it goes. I am decreasing the size by changing the values (rock.Xscale) and (rock.Yscale) and it works. It gets smaller as it goes.

The problem is the reference is still the at the old original size and the ball ends up small but “rolling” above the ground, as if it’s floating.

Is there any solution that anyone can think of? I would be so grateful and have spent alot of time trying to find a workaround!

This is using the Beta Windows version 2011.288 (for Android). Thx!

[import]uid: 33005 topic_id: 6868 reply_id: 306868[/import]

you need to remove the physics object and recreate it every time it gets smaller. (an unfortunate requirement of box2D for changing object size) you can’t do this in a collision event… a safe place to do it is in your enterFrame event. remember to keep track of the current rotation, velocity etc though so you can add those back onto the new object.

since the user only sees updates every frame anyway, they won’t be able to tell the difference

so when you need to change size, set a flag something like, say:

[lua]newBallProps = { radius=newRadius, x=newX, y=newY, rotation=newRotation… etc }[/lua]

and then in your enterFrame

[lua]if(newBallProps~=nil) then
changeBall()
end if[/lua]

then in your [lua]changeBall[/lua] function

[lua]function changeBall()
– remove old ball then
– process newBallProps and make new ball body
– etc etc
– then clear the flag:
newBallProps=nil
end[/lua]

instead of [lua]newBallProps[/lua] you could alternatively just have a flag say [lua]doChangeBall=true[/lua] and then in your changeBall function work out the relevant new properties from there…same difference

[import]uid: 6645 topic_id: 6868 reply_id: 23970[/import]