- Home /
Projetil rotation in straight line trajectory
Good evening, I would like a help in a script, with a 2D game TopDown, I wish the enemies could throw arrows, straight line, but fowards the player, however, I could not make the arrow sprite spin on its axis Without affecting the straight trajectory. Tips to incorporate?
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Blast : MonoBehaviour {
public float speed;
public GameObject player;
private Rigidbody2D myRigidbody;
private Animator anim;
public Vector3 vDirection;
public float angle;
// Use this for initialization
void Start () {
myRigidbody = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
vDirection = player.transform.position - gameObject.transform.position;
vDirection = vDirection.normalized;
}
void Update () {
player = BlasterAttack.PlayerT;
myRigidbody.velocity = transform.TransformDirection (vDirection * speed);
}
Answer by Woltus · Jun 05, 2017 at 12:13 AM
Set sprite as a child of arrow Game Object. Move that Game Object and spine the child.
Answer by Piyush_Pandey · Jun 01, 2017 at 10:22 AM
If you are translating and rotating the same object, then its trajectory will change.
1) Make a parent of the arrow. Do all the translations to this guy.
2) Now the arrow will follow the translation of its parent. Now perform all your rotations to this guy.
Your answer
![](https://koobas.hobune.stream/wayback/20220612123015im_/https://answers.unity.com/themes/thub/images/avi.jpg)