Hi All,
I’m having some issues at the moment with a physics body in a game I’m working on. Basically the idea is I have a fan which is spinning which has a physics body set up on it. I want to have this fan moving on the screen (could be moving in any direction) as well as spinning at the same time. The issue I’m having is if I use a transition to rotate the fan when an object collides with it, it doesn’t bounce away correctly it kind of sticks to the object.
I did a bit of reading around the place and seen that you can use motors to get a similar effect. I tried this which worked great as far as physics goes, but when the object moves side to side the fans rotation speed isn’t constant and will change depending where in the animation it is.
To move the fan side to side I have a loop which moves through different transitions which looks like this:-
--Object Animation
function animateScreenObject(screenObj)
animStep = screenObjects[screenObj]['animationStep']
animXpos = screenObjects[screenObj]['animation'][animStep \* 3 + 2] + (screenObjects[screenObj]['width'] / 2)
animYpos = screenObjects[screenObj]['animation'][animStep \* 3 + 3] + (screenObjects[screenObj]['height'] / 2)
animSpeed = screenObjects[screenObj]['animation'][animStep \* 3 + 1] + 0
screenObjects[screenObj]['animationStep'] = screenObjects[screenObj]['animationStep'] + 1
if screenObjects[screenObj]['animationStep'] \>= #screenObjects[screenObj]['animation'] / 3 then
screenObjects[screenObj]['animationStep'] = 0
end
loopAnimation = function()
animateScreenObject(screenObj)
end
screenObjects[screenObj]['transition'] = transition.to(screenObjects[screenObj]['object'], {x = animXpos, y = animYpos, time = animSpeed, onComplete = loopAnimation, transition=easing.inQuad })
screenObjects[screenObj]['object']['transition'] = screenObjects[screenObj]['transition']
end
To set up the motor I have this (please note, I don’t full understand how motors work… I have a feeling I could possibly use this method just need to change something here)
screenObjects[#screenObjects]['object'].bodyType = 'dynamic'
screenObjects[#screenObjects]['joint'] = physics.newJoint( "pivot", anchor, screenObjects[#screenObjects]['object'], screenObjects[#screenObjects]['object'].x, screenObjects[#screenObjects]['object'].y )
screenObjects[#screenObjects]['joint'].maxMotorTorque = 10
screenObjects[#screenObjects]['joint'].motorSpeed = -200
This method the physics seems to work better (so bounces off the blades correctly) but the blade speed is constantly changing through out the animation between positions. I thought it could have been the position relative to the joint, so I created a joint which moves with the object but it had the same affect unfortunately.
The test I’m doing for rotations at the moment is just
transition.to(screenObjects[#screenObjects]['object'], {rotation = -8000,time = 100000})
It’s very primitive I know… I originally had some code which handled it much better but took it out as using this system when an object collides with it, it will stick to it and not bounce off correctly.
I was going to make a video of it, but unfortunately I’m running late for work. Thought I’d post this for now and see if anyone can offer any suggestions as to what I can do to get this working properly. I’m only knew to corona and I’m sure I’m over looking something simple… Unfortunately I just can’t figure out what it could be looking at examples / documentation / forums at the moment. If anyone can point me in the right direction, it would be greatly appreciated!
Thanks in advance,
Stevil [import]uid: 133056 topic_id: 28249 reply_id: 328249[/import]
[import]uid: 52491 topic_id: 28249 reply_id: 114204[/import]
[import]uid: 133056 topic_id: 28249 reply_id: 114239[/import]
[import]uid: 52491 topic_id: 28249 reply_id: 114442[/import]