Question by
Shadowlash1221 · Jan 20, 2016 at 05:10 AM ·
2drotationprojectile
Spin Projectile?
So iv'e got my projectile moving perfectly but i need one thing, how do i rotate it the way it's facing on the z axis? I used an animation but it only rotated right, what do i do? Please help me, thanks
using UnityEngine;
using System.Collections;
public class StarProjectile : MonoBehaviour {
[HideInInspector] public bool facingRight = true;
public Rigidbody2D projectile;
void Update()
{
if (Input.GetButtonDown ("Fire1")) {
Rigidbody2D clone;
clone = Instantiate (projectile, transform.position, transform.rotation) as Rigidbody2D;
if (facingRight)
clone.velocity = transform.TransformVector (50 * Vector3.right);
else
clone.velocity = transform.TransformVector (-50 * Vector3.right);
}
}
void OnTriggerEnter2D(Collider2D other) {
if(other.gameObject.tag == "Enemy")
{
DestroyObject(other.gameObject);
}
}
}
Comment
Please, explain how you want it to be rotated. Draw some pictures or something like this. You are posting the script I did for you, but keep in $$anonymous$$d that we can't make a game for you, only help. :)
I wanted to see how to make it rotate rotate left when the player throws it left and rotate it right when the player throws it right. I made this script but it didn't work :/
using UnityEngine;
using System.Collections;
public class StarRotate : $$anonymous$$onoBehaviour {
[HideInInspector] public bool facingRight = true;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (facingRight)
transform.Rotate (Vector3.right * Time.deltaTime);
else
transform.Rotate (Vector3.left * Time.deltaTime);
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612060913im_/https://answers.unity.com/themes/thub/images/avi.jpg)