need help in changing behavior value during the game
by Ghonium · in iTorque 2D · 01/09/2012 (10:40 am) · 5 replies
hello
please if some one can help me
I have a behavior called PlayerControlsBehavior
it have a template
during the game on play I want when I touch the power speed button to change acceleration of the player from 2 to 10
is this possible to change the behavior acceleration value during the game?
please if some one can help me
I have a behavior called PlayerControlsBehavior
it have a template
%template.addBehaviorField(acceleration, "Forward acceleration (world units per second)", float, 2.0);
during the game on play I want when I touch the power speed button to change acceleration of the player from 2 to 10
function speedButton::onTouchDown(%this, %touchID, %worldPos)
{
echo("Finger " @ %touchID @ " touched the thing at " @ %worldPos);
//On touch speed button
if($item[1] > 0) //if i have power
{
//remove 1 power from item
$item[1] -= 1;
speedQuantityGui.setValue($item[1]);
SaveItems();
speedButton.Visible = 0;
schedule(3000, 0, "ShowSpeed");
speedme();
// I want to change the behavior acceleration here from 2 to 10 to give the player speed
}is this possible to change the behavior acceleration value during the game?
About the author
#2
I will check the featureDemo
actually all what I need to change the speed of the player if I touch the button of speed
and im still on learning as beginner
01/09/2012 (11:56 am)
thanks for the replayI will check the featureDemo
actually all what I need to change the speed of the player if I touch the button of speed
and im still on learning as beginner
#3
%theBehavior.acceleration = 10
or whatever value you want :)
01/10/2012 (1:05 am)
In that case all you need is a variable holding the behavior lets say %theBehavior and then you can use%theBehavior.acceleration = 10
or whatever value you want :)
#4
i tried to put it like
player.acceleration = 10;
it didnt work
i will try again
01/12/2012 (1:00 am)
the character name is playeri tried to put it like
player.acceleration = 10;
it didnt work
i will try again
#5
%this.acceleration on the behavior it self
I feel there is better solution that what i did but I dont know
still beginner
I cant think of better solution :)
01/12/2012 (1:48 am)
I solve it by adding global variable that will change%this.acceleration on the behavior it self
I feel there is better solution that what i did but I dont know
still beginner
// A timer will start and on its on zero sec it will start ShowSpeed function
schedule(3000, 0, "ShowSpeed");
$myChickenSpeed = 1;function MyChickenControlsBehavior::onUpdate(%this)
{
//use this if I press speed button
if($myChickenSpeed == 1)
{
%this.acceleration = 20;
}
//Acceleration will back to default after speed time done
if($myChickenSpeed == 0)
{
%this.acceleration = 8;
}
%this.owner.setImpulseForcePolar(%this.owner.rotation, (%this.up - %this.down) * %this.acceleration);
%this.owner.setAngularVelocity((%this.right - %this.left) * %this.turnSpeed);
}I cant think of better solution :)
Torque 3D Owner Marc Dreamora Schaerer
Gayasoft
The featureDemo has the timerShoots behavior for example where the projectile is cloned like this.
If you talk about the value on the template itself then no, thats the 'blueprint'. You would ahve to use a global variable to store the 'current to be used' acceleration and make all new objects that use this behavior read that global value and change their acceleration to it