actions on collisions

Hi,
first post here as I cannot find the answer as there seems to be so many options.

Scenerio:
I have an object, for example a feather.
I have another object for example a hairdryer.

I intend to move the feather with the hairdryer in all directions, left,right,up,down.
My issue is this, I do not want the hairdryer to touch the feather, the closer the dryer gets to the feather the more force is applied to the feather from the dryer.
Should I extend the collision boundary around the feather?
I’ve been playing around with this for a few hours now and seem to be hitting a wall on what seems like a simple task.
I thought of being able to apply different gravity on a single object then using linearForce/ angularForce to move it around but as Gravity is Global I cant.
Perhaps I am getting carried away with the lighter than air(gravity)issue and should transition the feather around once force is applied?

Any help /pointers /known tuts greatly appreciated.

[import]uid: 127675 topic_id: 29835 reply_id: 329835[/import]

Take a look at the draggable fan demo:

http://springboardpillow.blogspot.co.uk/2012/04/sample-code.html

In short, you need to calculate the force based on the distance of the object from the hairdryer. Start with a maximum radius of effect around the hairdryer and use the distance of the leaf to the max radius as the force, if the leaf is within the effect radius.

Once you have that amount of force use the angle of the leaf in relation to the hairdryer to apply force in that direction. The way I did this was to put a point at (10,0) and rotate it to the same angle as the leaf, around the hairdryer. Then extend the rotated point to the same distance as the amount of force to be used. Then simply apply the value you have to the leaf as parameters to the applyForce() function.

Please let me know if this is too confusing and I will try to explain it in diagram form. The draggable fan demo does all that but I have been told it’s a bit messy!

Matt. [import]uid: 8271 topic_id: 29835 reply_id: 119629[/import]

Using a slightly larger collision area and then applying force on collision would be a suitable way of handling this; just remember force stacks so start with a lower force and scale up. [import]uid: 52491 topic_id: 29835 reply_id: 119630[/import]

Horace,I had a look at that and to be honest it seems very complex for my level of coding, I 'am a web designer and have a very graphic focused background, however I have been around around flash from day 1 and do use action-script quite often.
I actually do borrow code that has already been written, who doesn’t?, but I like to be able to understand what is going on. Is there a simpler solution I wonder?

Peach, If I increase the collision area around the object it will interact with other objects on screen, is it possible to have the interaction between the hairdryer and feather only?
Again if possible could you point me at a suitable reference or code snippet please?
And I have to just say this however unprofessional, I am sure its been said before, but girl+programming skills+great looking = babe. sorry Peach its a compliment .:slight_smile: [import]uid: 127675 topic_id: 29835 reply_id: 119731[/import]

I agree that my solution is a complex one, but think about how it can be represented graphically (visually represent the joints) and you might see what I mean.

For Peach’s solution you can set collision filters on the objects so that only the collision area and the objects it should affect will touch each other. The collision area would need isSensor=true. You would need to calculate the direction from the moving object toward the centre of the platform to find the value of force to apply, if I understand her solution. [import]uid: 8271 topic_id: 29835 reply_id: 119735[/import]

I wouldn’t take it any other way; thank you, am flattered :slight_smile:

One option might be making it a sensor - though Horacebury’s solution, while a tad complex, may indeed be worth looking at. [import]uid: 52491 topic_id: 29835 reply_id: 119841[/import]

@bubblebobble,

Unfortunately there isn’t a much easier way if you want it to look/work accurately.

I would approach it similarly, but just slightly differently, to the other suggestions. Put a circular “range” sensor around the dryer. When the feather enters this sensor, start a Runtime listener that checks each frame and compares the location of the feather and the dryer. Get both the X and Y difference between them. You won’t need to do any fancy vector/angle trigonometry, since the applyForce() function takes linear values as its parameters… thus, you only need the linear differences. Then, apply an inverse force to the feather based on these values, adjusted to a very small fraction because applyForce() can be VERY strong and blow an object into the 5th dimension if you’re not careful! Finally, when the feather exits the sensor range, stop the Runtime listener.

For example, let’s assume the feather falls directly down on the dryer, located at coordinates 0,200. When it hits the sensor, the feather might be at 0,-100. Subtract the respective values and then negate to get “inverse” forces of 0,-300.

(fanY - featherY) * -1 = opposing force

Now, the feather is far away at this point so you need to “flip” this value by dividing 1 by it.

1/-300 = -0.0033333333.

Simply apply this force to your feather for the Y force parameter! Again, you might need to adjust this even further, by a factor higher or lower, depending on your physics setup, gravity, etc.

Presumably the feather will continue falling a bit. No problem. Let’s say it reaches 0,-50. Dryer remains at 0,200. The formula yields -250 in this case. 1/-250 = -0.004. As you can see, the result is a stronger opposing force as the feather gets nearer. If it somehow gets down to 0,180, that’s just a difference of 20, and the end result is -0.05… considerably higher than our previous values of 0.004 and 0.003333.

Obviously this will work for the X calculations too.

And, for setting up collision filters so that the dryer sensor only reacts with the feather, please refer to my helper chart here:
http://developer.coronalabs.com/forum/2010/10/25/collision-filters-helper-chart

Hope this helps!
Brent Sorrentino

[import]uid: 9747 topic_id: 29835 reply_id: 119847[/import]

@bubblebobble If you’ve not got your code doing what you want yet, would you be able to provide a diagram and I’ll code it up? [import]uid: 8271 topic_id: 29835 reply_id: 119854[/import]

@Brent,
thanks for that, the collision detection filter chart looks good and good explanations too; I am definitely looking at that.

@Peach,
yes the sensor seems to be suggested by everyone, I will start to play with that.

@Horace,
seems your idea is the way forward as discussed, Thank you for the offer, I am going to have a much closer look at your code in order to get a better understanding of it ( may take a few years!, joking), then see if I can implement it.
If I have issues which I am unable to resolve I would like to take you up on your offer even if its just a quick framework I could work with.

What I want to achieve can be seen in a flash style game I know of, well the physics can be.

I am all up to date work wise today so I am dedicating some of today to this problem, how exciting ! well it is when its solved.

Really good answers here that are much appreciated.

BB

[import]uid: 127675 topic_id: 29835 reply_id: 119858[/import]

Take a look at the draggable fan demo:

http://springboardpillow.blogspot.co.uk/2012/04/sample-code.html

In short, you need to calculate the force based on the distance of the object from the hairdryer. Start with a maximum radius of effect around the hairdryer and use the distance of the leaf to the max radius as the force, if the leaf is within the effect radius.

Once you have that amount of force use the angle of the leaf in relation to the hairdryer to apply force in that direction. The way I did this was to put a point at (10,0) and rotate it to the same angle as the leaf, around the hairdryer. Then extend the rotated point to the same distance as the amount of force to be used. Then simply apply the value you have to the leaf as parameters to the applyForce() function.

Please let me know if this is too confusing and I will try to explain it in diagram form. The draggable fan demo does all that but I have been told it’s a bit messy!

Matt. [import]uid: 8271 topic_id: 29835 reply_id: 119629[/import]

Using a slightly larger collision area and then applying force on collision would be a suitable way of handling this; just remember force stacks so start with a lower force and scale up. [import]uid: 52491 topic_id: 29835 reply_id: 119630[/import]

Horace,I had a look at that and to be honest it seems very complex for my level of coding, I 'am a web designer and have a very graphic focused background, however I have been around around flash from day 1 and do use action-script quite often.
I actually do borrow code that has already been written, who doesn’t?, but I like to be able to understand what is going on. Is there a simpler solution I wonder?

Peach, If I increase the collision area around the object it will interact with other objects on screen, is it possible to have the interaction between the hairdryer and feather only?
Again if possible could you point me at a suitable reference or code snippet please?
And I have to just say this however unprofessional, I am sure its been said before, but girl+programming skills+great looking = babe. sorry Peach its a compliment .:slight_smile: [import]uid: 127675 topic_id: 29835 reply_id: 119731[/import]

I agree that my solution is a complex one, but think about how it can be represented graphically (visually represent the joints) and you might see what I mean.

For Peach’s solution you can set collision filters on the objects so that only the collision area and the objects it should affect will touch each other. The collision area would need isSensor=true. You would need to calculate the direction from the moving object toward the centre of the platform to find the value of force to apply, if I understand her solution. [import]uid: 8271 topic_id: 29835 reply_id: 119735[/import]

I wouldn’t take it any other way; thank you, am flattered :slight_smile:

One option might be making it a sensor - though Horacebury’s solution, while a tad complex, may indeed be worth looking at. [import]uid: 52491 topic_id: 29835 reply_id: 119841[/import]

@bubblebobble,

Unfortunately there isn’t a much easier way if you want it to look/work accurately.

I would approach it similarly, but just slightly differently, to the other suggestions. Put a circular “range” sensor around the dryer. When the feather enters this sensor, start a Runtime listener that checks each frame and compares the location of the feather and the dryer. Get both the X and Y difference between them. You won’t need to do any fancy vector/angle trigonometry, since the applyForce() function takes linear values as its parameters… thus, you only need the linear differences. Then, apply an inverse force to the feather based on these values, adjusted to a very small fraction because applyForce() can be VERY strong and blow an object into the 5th dimension if you’re not careful! Finally, when the feather exits the sensor range, stop the Runtime listener.

For example, let’s assume the feather falls directly down on the dryer, located at coordinates 0,200. When it hits the sensor, the feather might be at 0,-100. Subtract the respective values and then negate to get “inverse” forces of 0,-300.

(fanY - featherY) * -1 = opposing force

Now, the feather is far away at this point so you need to “flip” this value by dividing 1 by it.

1/-300 = -0.0033333333.

Simply apply this force to your feather for the Y force parameter! Again, you might need to adjust this even further, by a factor higher or lower, depending on your physics setup, gravity, etc.

Presumably the feather will continue falling a bit. No problem. Let’s say it reaches 0,-50. Dryer remains at 0,200. The formula yields -250 in this case. 1/-250 = -0.004. As you can see, the result is a stronger opposing force as the feather gets nearer. If it somehow gets down to 0,180, that’s just a difference of 20, and the end result is -0.05… considerably higher than our previous values of 0.004 and 0.003333.

Obviously this will work for the X calculations too.

And, for setting up collision filters so that the dryer sensor only reacts with the feather, please refer to my helper chart here:
http://developer.coronalabs.com/forum/2010/10/25/collision-filters-helper-chart

Hope this helps!
Brent Sorrentino

[import]uid: 9747 topic_id: 29835 reply_id: 119847[/import]

@bubblebobble If you’ve not got your code doing what you want yet, would you be able to provide a diagram and I’ll code it up? [import]uid: 8271 topic_id: 29835 reply_id: 119854[/import]

@Brent,
thanks for that, the collision detection filter chart looks good and good explanations too; I am definitely looking at that.

@Peach,
yes the sensor seems to be suggested by everyone, I will start to play with that.

@Horace,
seems your idea is the way forward as discussed, Thank you for the offer, I am going to have a much closer look at your code in order to get a better understanding of it ( may take a few years!, joking), then see if I can implement it.
If I have issues which I am unable to resolve I would like to take you up on your offer even if its just a quick framework I could work with.

What I want to achieve can be seen in a flash style game I know of, well the physics can be.

I am all up to date work wise today so I am dedicating some of today to this problem, how exciting ! well it is when its solved.

Really good answers here that are much appreciated.

BB

[import]uid: 127675 topic_id: 29835 reply_id: 119858[/import]