Making Hanzo’s Scatter Arrow in 2D
I'm trying to make a very basic version of Hanzo's Scatter Arrow from Overwatch in 2D. It's pretty simple on paper - on collision, delete the fired arrow and create three in its place, that fan out from the collision point. These particular arrows are destroyed on the next collision.
I'm having the most trouble generating the new arrows and passing the velocity from the original arrow onto the three that are generated.
Currently, the scatter arrow can spawn three arrows, but on collision they stop moving. I've been stuck on it for weeks - my assumption it has something to do with the velocity and when to set the velocity of the new arrows. Any help would be greatly appreciated - thanks!
Scatter Arrow Prefab
public class ScatterArrow : MonoBehaviour {
Rigidbody2D rb;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update () {
}
void OnCollisionEnter2D (Collision2D coll)
{
for (int i = 0; i < 3; i++){
GameObject aFS = Instantiate (Resources.Load ("ArrowFromScatter")) as GameObject;
aFS.transform.position = coll.contacts [0].point;
ArrowFromScatter arrowScript = aFS.GetComponent<ArrowFromScatter> ();
//arrowScript.rigidBody.velocity = rb.velocity;
}
Destroy (this.gameObject);
}
}
Arrow From Scatter Prefab
public class ArrowFromScatter : MonoBehaviour {
public Rigidbody2D rigidBody;
// Use this for initialization
void Start () {
rigidBody = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update () {
}
}
Your answer
Follow this Question
Related Questions
2D player slower on ground than in air 1 Answer
Rigidbody2D moving WAY to fast 1 Answer
Climbing code problem (2d physic). 0 Answers
Player randomly stops moving 1 Answer
Adding velocity to an object in a brick breaker game 0 Answers