I have huge problem with my code. Im trying to make a easy shooter, and the one and only weapon are missiles. When my object stays in place, everything is ok, but when i start to move, my missiles dont fly straight forward ! Sometimes they even fly sideways !
I have totally no idea what’s wrong with this… Here is my code
var moveLeftPad : Joystick;
var moveRightPad : Joystick;
var poweron : Joystick;
var actionPad : Joystick;
var Speed : float = 15;
var tylboos : ParticleEmitter;
var praboos : ParticleEmitter;
var lewboos : ParticleEmitter;
var pocisk : Rigidbody;
private var thisTransform : Transform;
private var character : Rigidbody;
function Start()
{
tylboos.emit = false;
praboos.emit = false;
lewboos.emit = false;
thisTransform = GetComponent( Transform );
character = GetComponent( Rigidbody );
}
function Update()
{
tylboos.emit = false;
praboos.emit = false;
lewboos.emit = false;
var power = poweron;
var forward : Vector3 = transform.TransformDirection(Vector3.forward);
var touchLeft = moveLeftPad;
var touchRight = moveRightPad;
var action = actionPad;
if ( power.IsFingerDown() )
{
character.AddForce(forward * Speed);
tylboos.emit = true;
praboos.emit = true;
lewboos.emit = true;
}
if ( touchRight.IsFingerDown() )
{
lewboos.emit = true;
transform.Rotate(Vector3.up *3);
}
if ( touchLeft.IsFingerDown() )
{
praboos.emit = true;
transform.Rotate(Vector3.down *3);
}
if ( action.IsFingerDown() )
{
var clone : Rigidbody;
clone = Instantiate(pocisk, character.position, transform.rotation);
clone.velocity = transform.TransformDirection(Vector3.forward*50);
}
}