Hi, i try to create myself a mini-game like this : habrahabr.ru/post/265749/ from 1vanK ( thank for that )
and i’ve got a problem when i call inside my script :
Node@ newNodeParticle = scene.InstantiateXML(smoke_xml, position, Quaternion(0.0f, yaw, pitch));
i call this method when i shoot a bullet , but, i noticed a small freeze when i use particle. but not when i use the bullet only without particle.
the problem is the same with the 1vank’s demo ( only for the first bullet , me , for all bullet… )
it is possible to “preload” the xml file to prevent the freeze ?
the complete script :
[code]class Canon : ScriptObject{
float pitch = 0.0f;
float yaw = 0.0f;
float shootDelay = 0.0f;
XMLFile@ bullet_xml = cache.GetResource("XMLFile", "Objects/bullet.xml");
XMLFile@ smoke_xml = cache.GetResource("XMLFile", "Objects/smokeCanon.xml");
void Update(float timeStep){
if (input.keyDown[KEY_UP]){
pitch += 45 * timeStep;
}
if (input.keyDown[KEY_DOWN]){
pitch -= 45 * timeStep;
}
if (input.keyDown[KEY_RIGHT]){
yaw += 20 * timeStep;
}
if (input.keyDown[KEY_LEFT]){
yaw -= 20 * timeStep;
}
if( yaw >= 100.0f){
yaw = 100.0f;
}
if( yaw <= 80.0f){
yaw = 80.0f;
}
if (input.keyDown[KEY_SPACE] && shootDelay <= 0.0f){
shootDelay = 1.0f;
Shoot();
}
pitch -= 1.5f * timeStep;
if (shootDelay > 0.0f)
shootDelay -= timeStep;
if( pitch >= -50.0f){
pitch = -50.0f;
}
if( pitch <= -95.0f){
pitch = -95.0f;
}
//node.rotation = Quaternion(pitch, yaw, 0);
node.GetChild("base",true).rotation = Quaternion(0, yaw, 0);
node.GetChild("canon",true).rotation = Quaternion(0, 0, pitch);
}
void Shoot()
{
Vector3 position = node.GetChild("hotpoint", true).worldPosition;
Node@ newNode = scene.InstantiateXML(bullet_xml, position, Quaternion());
Node@ newNodeParticle = scene.InstantiateXML(smoke_xml, position, Quaternion(0.0f, yaw, pitch));
RigidBody@ body = newNode.GetComponent("RigidBody");
body.ApplyImpulse( Quaternion(0.0f, yaw, pitch) * Vector3(0.0f,1.0f,0.0f) * 1950.0f);
}
}[/code]