- Home /
tranform.TransformDirection not effecting spawned object
Ok so I am making a little game to show off my game design abilities for a portfolio. I've used a similar script in the past but for some reason it will not move the game character(chicken) after they spawn. All other components of the script function and I do not have any errors showing up so how do I get the chickens to ove forward if this method isn't going to work? Please help.
var Chicken_gunSpeed : float = 15.0;
var chicken : Rigidbody;
var fireRate = 1;
private var nextFire = 1;
static var chickenOn : boolean = false;
function Update () { if(Time.time > nextFire) { nextFire = Time.time + fireRate * Random.Range(2,5);
var cloneball = Instantiate (chicken, transform.position, transform.rotation);
cloneball.velocity = transform.TransformDirection (Vector3.forward * 50); }
}
You should probably use Transform.InverseTransformDirection, since Vector3.forward is in world space. However, transform.InverseTransformDirection(Vector3.forward) is the same as transform.forward, except without the additional calculation (I think). Why not just cloneball.velocity = transform.forward * -50?
Still didn't work, Chicken remains running in place.
You may need to call the Rigidbody.WakeUp method to activate the rigidbody
Answer by ScroodgeM · Aug 17, 2012 at 07:26 AM
function Update () { if(Time.time > nextFire) { nextFire = Time.time + fireRate * Random.Range(2,5); var cloneball : Rigidbody; cloneball = Instantiate (chicken, transform.position, transform.rotation); //r u sure you want to make speed to backward??? cloneball.velocity = transform.forward * -50; } }
Found the problem with the commands the object was receiving. The "cloneball.velocity = transform.forward * 50;" did the trick, thanks for responding to my question and getting an answer to me quickly.
Answer by LeathalNinja1986 · Aug 20, 2012 at 04:11 PM
Script has no effect on the checkens movement after it spawns still.
How would I merge that Rigidbody.WakeUp to my script? I'm not familiar with it.
None, had to make a couple tweaks so the characters move in the correct direction but no errors occurred.
does rigidbody is not set to kinematic?
check cloneball.velocity after applying the speed using Debug.Log() - what you see?