May 23, 2012, 12:22:09 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Please report any bugs or issues that you might be encountering with the Beta in the Support System so that we can better keep track of any oustanding issues that may come up.

GameCore Support System
 
   Home   Help Search Login Register  
Pages: 1 [2]
  Print  
Author Topic: AddForce  (Read 1844 times)
Squat
Hero Member
*****
Posts: 592


View Profile
« Reply #15 on: January 28, 2009, 04:54:34 PM »

The force must be added against the collision mesh.

Quote
   
Vector MyPop;

Object@ newobject = GetGameManager().GetWorld().AddObject("newobject", "newobject.opr");
    newobject.SetPosition(object.GetPosition());
    
    ObjectCollide@ base = newobject.GetCollideObject( "base");

    MyPop.x=0;
    MyPop.y=100;
    MyPop.z=0;
    base.AddForce( MyPop);
    newobject.UpdateCollisionObjectPositions();

This will spawn an object and kick it upwards. ( stripped it down, may not work as-is. This functions in the debris sample I gave everybody, in the Gibs.gsl)


Regular forces are added per object. Area force should affect all objects in the area. You can use both, but you may have to cycle the objects that are within a particular distance and hit each one individually. At least then you can turn on and off objects to get affected by this particular kind of force.
« Last Edit: January 28, 2009, 06:43:06 PM by Squat » Logged
pixel_legolas
Hero Member
*****
Posts: 786


View Profile
« Reply #16 on: January 28, 2009, 05:26:53 PM »

Well straight of it did not work as you said, still complaining that AddForce has wrong input
Logged
Squat
Hero Member
*****
Posts: 592


View Profile
« Reply #17 on: January 28, 2009, 06:49:51 PM »

I updated the script, it works now:

Quote
Vector MyPop;

void Initialize( Object@ object)
{

    Object@ newobject = GetGameManager().GetWorld().AddObject("newobject", "A_Block.opr");
    newobject.SetPosition(object.GetPosition());
    
    ObjectCollide@ base = newobject.GetCollideObject( "base");

    MyPop.x=0;
    MyPop.y=1000;
    MyPop.z=0;
    base.AddForce( MyPop);
    newobject.UpdateCollisionObjectPositions();

}
Logged
Ransom
Full Member
***
Posts: 132



View Profile
« Reply #18 on: January 28, 2009, 08:52:09 PM »

I forgot, AddAreaForce requires two additional parameters.  It should be AddAreaForce(Vector(WorldCoordinates),Float RangeOfForce, Float ForceAmount);

This sample will apply force to any object within the area (except the object calling the command)...
Quote
object.SetCollisionEnabled( false);
   GetGameManager().GetWorld().AddAreaForce(object.GetPosition(), 20, 100);
   object.SetCollisionEnabled(true);
« Last Edit: January 28, 2009, 08:53:42 PM by Ransom » Logged
pixel_legolas
Hero Member
*****
Posts: 786


View Profile
« Reply #19 on: January 29, 2009, 03:11:04 AM »

Ransom, your script was shortest so i tried it and it works perfectly Smiley Now the only strange thing is that it's activated instantly. Before when i pressed E it started an animation event but this addareaforce starts directly. I have a box close to character that flies away instantly, pretty neat i must say
Logged
Ransom
Full Member
***
Posts: 132



View Profile
« Reply #20 on: January 29, 2009, 08:52:20 AM »

If you want it to work with a key press, put a bool inside your E key section of HandleEvent.  Declare the bool at the top of the script first, as false.

Quote
//pseudo code

Epressed = false;


HandleEventSection
{

if(EpressedSection)
Epressed = true;

}

Then wrap the earlier script snippet with this...
Quote
if(Epressed)
{
Epressed = false;
object.SetCollisionEnabled( false);
   GetGameManager().GetWorld().AddAreaForce(object.GetPosition(), 20, 100);
   object.SetCollisionEnabled(true);
}

That should work so that the force is only applied when you press your key.
Logged
pixel_legolas
Hero Member
*****
Posts: 786


View Profile
« Reply #21 on: January 29, 2009, 10:16:08 AM »

Thanks for coming up with code so fast. Tried this morning to add a IF command but i did something wrong. Will try this later on to see the result.

I also wan to play an animation, sound and fx, do i add this at same place? Or is there a more efficient place to put it?

edit: just found that destructable object.gsl has alot of info, also attaching fx so will look more at that one
« Last Edit: January 29, 2009, 11:34:37 AM by pixel_legolas » Logged
pixel_legolas
Hero Member
*****
Posts: 786


View Profile
« Reply #22 on: January 29, 2009, 01:44:39 PM »

Hm, here is what i have but does not work:

Quote
if (params.stringValue == "die")
      {
        diePressed = params.floatValue;
        if (diePressed > 0.5)
        diePressedis = true;
            object.SetCollisionEnabled( false);
   GetGameManager().GetWorld().AddAreaForce(object.GetPosition(), 20, 100);
   object.SetCollisionEnabled(true);
         return true;

        }

What happens is that now when i press E i get the animation but still the box flies away. I thought that this script searches the floatvalue and if its above 0.5 it then uses addareaforce. Now it seems the float is above 0.5 even if i am not pressing
Logged
Ransom
Full Member
***
Posts: 132



View Profile
« Reply #23 on: January 29, 2009, 03:56:51 PM »

All you've done there is set diePressedis to true.  You need to use open and close brackets to encompass the entire snippet.

Quote
if (diePressed > 0.5)
{
        diePressedis = true;
            object.SetCollisionEnabled( false);
   GetGameManager().GetWorld().AddAreaForce(object.GetPosition(), 20, 100);
   object.SetCollisionEnabled(true);
}


Logged
Squat
Hero Member
*****
Posts: 592


View Profile
« Reply #24 on: January 29, 2009, 04:08:47 PM »

Quote
if (diePressed > 0.5)
        diePressedis = true;
            object.SetCollisionEnabled( false);

=

Quote
if (diePressed > 0.5) diePressedis = true;
object.SetCollisionEnabled( false);

Without brackets, IF takes only the very next command.
Logged
pixel_legolas
Hero Member
*****
Posts: 786


View Profile
« Reply #25 on: January 29, 2009, 04:43:03 PM »

Flawless!

Now i wanted to add some sound but the code probably makes a loop because the sound keeps repeating ultrafast. New code:

Quote
if (params.stringValue == "die")
      {
        diePressed = params.floatValue;
        if (diePressed > 0.5)
        {
        diePressedis = true;
            object.SetCollisionEnabled( false);
            
   GetGameManager().GetWorld().AddAreaForce(object.GetPosition(), 20, 100);
   object.SetCollisionEnabled(true);
   }
   if (diePressed >0.9)
   {
   GetFXManager().PlaySample("anger.smp");
   }
         return true;

        }

I guess if i add a fx it will also spawn all the time.

The problem is this, when i press E it doesnt play animation or anything, i have to hold the key in to make it happen and then it loops everything. Are there any easy setups for doing things once even if i hold the key E in?
Logged
Squat
Hero Member
*****
Posts: 592


View Profile
« Reply #26 on: January 29, 2009, 05:41:40 PM »

I dont' actually see the line to play an animation in that code

Basically set the function up inside the dynamics advance and wrap it in a if(Fired) and then use your handle-event to set that "Fired" to true. At the end of the entire cycle, have the dynamics advance function set it to false and it will shut off for the next press. You can then tell it not to let you fire again until it's finished. You could also work in a way for players to time combos, using the floating seconds.

Try to avoid writing code into GetControllerVariable. Rather, just try to take the message and return "die". Then in dynamics advance, you can say if(Die) instead of what I put as "Fired". Then set it to false. When you deal with controller variables, it's no longer Die = false; you would now say object.SetControllerVariable("Die", false);

Quote
if(Die)
{
play animation
play sound
Add force
if(done)
object.SetControllerVariable("Die", false);
}

Whatever you use for checking if it's done is up to you. For now, you may want to just use a time delay, which is pretty simple

Quote
bool done= false;
float time = 0;
float delay = 3;

dynamicsadvance()
if(!done)
{
    if(time>=delay)
   {
       done=true;
       time=0;
   }
   else
       time+=seconds;
}

The following appear quite handy indeed:

GetAnimRemainingTime
GetAnimTime
IsAnimFinished
IsAnimPlaying
« Last Edit: January 29, 2009, 06:27:26 PM by Squat » Logged
pixel_legolas
Hero Member
*****
Posts: 786


View Profile
« Reply #27 on: January 30, 2009, 05:04:14 AM »

Thanks, I will look into that piece of code and try to adapt it.

The Play animation is like all other animations.

You have a KeyE Die, in character.opr you have a LoadAnimation Die die.fbx

Now, when DiePressed has a float over 0 it will run animation. If I am correct Smiley
Logged
Pages: 1 [2]
  Print  
 
Jump to:  

 
Powered by MySQL Powered by PHP bluBlur Skin © 2006, hbSkins
Powered by SMF 1.1.14 | SMF © 2006-2011, Simple Machines LLC
Valid XHTML 1.0! Valid CSS!