Quantcast
Channel: Questions in topic: "side scroller"
Viewing all articles
Browse latest Browse all 72

Fire a Projectile towards a specific object?

$
0
0
I'm making a 2D Side Scroller and I'm trying to launch a projectile from an object called "StrawSpawn" towards and object called "Target" at a speed of 20. With my current code my projectile always fires off to screen right at a slight angle and nearly too fast to see, regardless of where "StrawSpawn" and "Target" are located relative to each other. Can someone take a look at my code and tell me what I'm doing wrong? Thanks. var projectile : Rigidbody; var speed = 20; function Update () { // Put this in your update function if (Input.GetButtonDown("Fire")) { // Instantiate the projectile at the position and rotation of this transform var clone : Rigidbody; clone = Instantiate(projectile, GameObject.Find("StrawSpawn").transform.position, transform.rotation); clone.velocity = transform.TransformDirection (GameObject.Find("Target").transform.position * speed); Destroy (clone.gameObject, 3); } }

Viewing all articles
Browse latest Browse all 72

Trending Articles



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