- Home /
Object Speed (transformDirection)
Hello! Need help!
In first script have:
public void shootingFunction(){
if(Input.GetMouseButtonDown(0) && Time.time > nextFire && isDead == false){
// The screen has been touched so store the touch
Touch touch = Input.GetTouch(0);
cameraComponent = GameObject.Find("CameraShot").GetComponent<Transform>();
cameraComponent.transform.position = -Dude.transform.position;
coorTouch = camaraShot.ScreenToWorldPoint(new Vector3(touch.position.x, touch.position.y, 10));
Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
}
}
and, in other script:
void OnEnable()
{
bullet.velocity = transform.TransformDirection (gameController.coordenadasTouch) * speed ;
}
ITS ALL OKEY! BUUUUUUUT!
It varies the speed where I touch the screen on the device. If I touch the screen at the top is very fast, if I touch near where the shot is generated is very slow! How do I make the speed handle "speed"??????????????
Transform.TransformDirection???
Answer by GenericToast · Sep 11, 2017 at 01:12 PM
So you're trying to shoot towards the direction of the touch?
Try this:
void OnEnable()
{
bullet.velocity = (gameController.coordenadasTouch - transform.position).normalized * speed;
}
The direction of the shot is correct. The problem is the speed. Depending on where i touch the screen is faster or slower. If i touch near where the "Shoot" is generales is very slow, if i touch far (top of the screen) is very fast. I need the speed to be constant, touch where i touch in the screen.
THAN$$anonymous$$ YOUUUUUU!