- Home /
Self Answered
problem with adding force
Hi All
I implemented a simple script to activate a coin object (from an object pool) , and add force to the coin so that it moves to the right. The idea is, when I kill an enemy object, a coin will be "spawned" and move to the right of the enemy object. There is also a drag force on the coin object so that the coin will eventually stop moving.
The problem is, it works most of the time. The enemy killed, coin spawned, moved and stopped. However, occasionally, the coin would not move at all!!! the coin just spawned and stayed where the enemy object was.
the code:
myCoins[i].rigidbody2D.AddForce(new Vector2(1.1f,0.0f) * _force);
I have been struggling with this for days and still cannot figure out the problem! any advice is much appreciated
Put a OnCollisionEnter() with a debug statement to see if the coins are colliding with something.
Answer by jim_bbq · Jul 11, 2014 at 01:48 PM
It seems that I have solved the problem.....the coins are children of a parent object (the map), I add the force before making the coin a child of the map...i just need to make sure I make the coin a child first before adding the force!
silly me