Quantcast
Channel: Questions in topic: "addforce"
Viewing all articles
Browse latest Browse all 1264

Instantiate a Gameobject and AddForce to it (Rigidbody2D)

$
0
0
I need to instantiate a GameObject at certain intervals from an empty gameobject called spawnpoint and add force to the instantiated object. With the script that I have written the initiated gameobject spawns and seems to move along the correct vector but after traveling for like 2 centimetres it almost like hits an invisible wall and falls down, even with a force of lets say 10000. The script is attached to the empty gameobject called spawnpoint. What should I do? I've read many answers here concerning the same subject but none of them have helped. Here's the code I have now: public class BombSpawnAddForce : MonoBehaviour { public Transform spawnPoint; public GameObject ballPrefab; public float delay = 0.01f; public float force = 0.01f; void Start () { InvokeRepeating ("Spawn", delay, delay); } void Spawn() { GameObject ballInstance; ballInstance = Instantiate (ballPrefab, spawnPoint.transform.position, spawnPoint.rotation) as GameObject; ballInstance.rigidbody2D.AddForce(new Vector2 (3,5) * force); } }

Viewing all articles
Browse latest Browse all 1264

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>