Hi Guys,
I have a game manager with a script that spawn a prefab.
It has this warning/error, though it’s still work but I would I like to solve it.
Error/warning message:
Actor::setLinearVelocity: Actor must be (non-kinematic) dynamic!
UnityEngine.Rigidbody:set_velocity(Vector3)
gameManager_script:SendEnemy() (at Assets/_scripts/gameManager_script.js:25)
gameManager_script:Start() (at Assets/_scripts/gameManager_script.js:12)
Below is the code,
#pragma strict
var enemySpwn1 : Transform;
var enemyTarg1 : Transform;
var enemyPrefab : GameObject;
var targetDir : Vector3;
private var enemySpeed = 0.1;
function Start () {
targetDir = enemyTarg1.position - enemySpwn1.transform.position;
SendEnemy ();
}
function Update () {
}
function SendEnemy()
{
var instantiatedProjectile : GameObject = Instantiate
(enemyPrefab, enemySpwn1.transform.position, this.transform.rotation);
//This is the one that is requiring my prefab
//(which is a empty game object added a rigid body) to be non-kinematic & to set velocity
instantiatedProjectile.rigidbody.velocity =
transform.TransformDirection(targetDir*enemySpeed);
}
In short, my prefab gameobject, (1) must turn off IsKinematic & (2) set velocity. But I don’t know how. I can turn it off, but it also means physics stuff will affect it, I want to learn how to solve it.
Any advice?
Thanks in advance.