- Home /
This question was
closed Jan 18, 2016 at 07:46 PM by
Victors for the following reason:
Problem is not reproducible or outdated
Rigidbody.AddForce giving wrong direction
Hello. I got a script for moving the "bullet", to be definitive, instantiating and giving the impulse to instantiated object. I tried a lot of cases, but the script doesn't working fine. The movement of bullet is horisontal or vertical, without rotation of parental object. This is script: using UnityEngine; using System.Collections; using UnityEngine.UI; // Required when Using UI elements.
public class FDSA : MonoBehaviour {
public float Power;
public Slider slider;
private FBSJ powerscript;
private FBSL handrotatencammovementscript;
private GameObject interfaceobject = null;
private GameObject pointwherebulletshot = null;
private Rigidbody2D rbullet;
private float forceduslider;
void Start () {
}
void Update () {
if(slider.value != 0){
int nbTouches = Input.touchCount;
if(nbTouches > 0)
{
for (int i = 0; i < nbTouches; i++)
{
Touch touch = Input.GetTouch(i);
if(touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled){
pointwherebulletshot = GameObject.FindGameObjectWithTag("shootpoint");
forceduslider = slider.value * 600F;
Debug.Log ("Sosisechka");
Vector3 positionofbullet = new Vector3(pointwherebulletshot.transform.position.x, pointwherebulletshot.transform.position.y, 0);
GameObject bullet = Instantiate(Resources.Load ("Bullet", typeof(GameObject)), positionofbullet, pointwherebulletshot.transform.rotation) as GameObject;
rbullet = bullet.GetComponent<Rigidbody2D>();
rbullet.AddForce (bullet.transform.localPosition.normalized * forceduslider * (-1F), ForceMode2D.Impulse);
}
}
}
}
}
}
Comment