May 23, 2012, 12:21:15 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)
pixel_legolas
Hero Member
*****
Posts: 786


View Profile
« on: January 21, 2009, 06:57:59 PM »

I have scanned some script and looked at the AddForce command.

I am trying to add force to my player when i press a button. I have this setup:

When pressing E my character does an attack animation. This is what i have in character.gsl:

Code:
if (params.stringValue == "die")
{
diePressed = params.floatValue;
                  return true;
        }

What i tried was adding this line:

Code:
object.GetWorld().GetObject("Player").AddForce(500);


I just get errors. When i try GetMesh i get error. When i change to @collideBase = object.GetCollideObject( "Base"); i get error

I just want a simple "press E and it will do the animation and add some force" Smiley


Logged
Ron
Sr. Member
****
Posts: 326


View Profile
« Reply #1 on: January 21, 2009, 07:25:52 PM »

I think you just need it in vector form so it also knows the direction to add the force in addition to the amount. Here it is from the vehicle script

Code:
float spoilerForce = speed * 125.0f;

collideBase.AddForce( -mtx.YAxis * spoilerForce);

if (spoilerForce >= 0)
{
body.AddForce( object.GetCurMatrix().Project( 0, -spoilerForce, 0));
}
Logged
Ron
Sr. Member
****
Posts: 326


View Profile
« Reply #2 on: January 22, 2009, 02:45:17 PM »

Here is another example (simpler) that may help

Code:
Vector Pos = object.GetPosition();
object.AddForce( Vector( Pos.x/1.5, 0, -Pos.z/1.5));
Logged
Squat
Hero Member
*****
Posts: 592


View Profile
« Reply #3 on: January 22, 2009, 03:02:00 PM »

Taken right out of Destructable.gsl

Quote
object.GetWorld().AddAreaForce( hitPosition, explodeRange, explodeForce);
Logged
Ransom
Full Member
***
Posts: 132



View Profile
« Reply #4 on: January 23, 2009, 09:46:51 AM »

AddAreaForce will affect any physics object in the area, not just the player.

Pixel - you need a pointer to the collision object first, which I think should already be declared in networkCharacter.  If not, use...

Quote
ObjectCollide@ base = object.GetCollideObject("Base");
//assuming Base is the name of the collision object

Then you just need to use a vector, like Ron said...

Quote
base.AddForce(ForceX,ForceY,ForceZ);



Logged
pixel_legolas
Hero Member
*****
Posts: 786


View Profile
« Reply #5 on: January 23, 2009, 12:23:12 PM »

i have tried all codes above before because i looked at scripts refernce and all the scripts in folder. But i still get error.

I declare ObjectCollide@ base = object.GetCollideObject("Base"); at top of character.gsl where i declare all else.

I then add the code in the HandleEvent like this:

Quote
if (params.stringValue == "die")
      {
         diePressed = params.floatValue;
          base.AddForce(5000,5000,5000);
         return true;
           
             
        }

But i get error in log:

Compiling ObjectCollide@ base
Compiling bool HandleEvent(Object@, const String&in, GameEventParams@)
Use of uninitialized global variable 'base'.
Incorrect number of parameters for function 'AddForce'
Logged
Ransom
Full Member
***
Posts: 132



View Profile
« Reply #6 on: January 23, 2009, 02:17:32 PM »

I'm sorry, you need to tell the engine your using a vector.  Use...
Quote
base.AddForce(Vector(ForceX,ForceY,ForceZ));

Also, you can't declare a pointer, using that method, in the Initialize section and have it read in another section.  You need to do it like this...
Quote
//In variables section at the very top
ObjectCollide@ base;

// then in initialize section
@base = object.GetCollideObject("Base");

Once you do that, you can simply use base.whatever anywhere in your script.

//edit: fixed typos
« Last Edit: January 24, 2009, 08:01:28 AM by Ransom » Logged
Squat
Hero Member
*****
Posts: 592


View Profile
« Reply #7 on: January 23, 2009, 02:48:35 PM »

I hate to be the bearer of good news, but "base" and "Base" are two completely separate words in GC. The game lost the pointer because you defined base, then called Base. At least, I'm hoping that's what happened. This works, I've got forces abound in GC.
Logged
Ransom
Full Member
***
Posts: 132



View Profile
« Reply #8 on: January 23, 2009, 02:54:55 PM »

yeah, but "base" is set up as a pointer to the collide object named "Base", so in this case, they are the same.
Logged
pixel_legolas
Hero Member
*****
Posts: 786


View Profile
« Reply #9 on: January 23, 2009, 08:28:40 PM »

hm, i just have no clue where to put stuff.

I add this at top where you declare stuff:

CollideObject@ base;

But i get an error already there Smiley
Logged
Ransom
Full Member
***
Posts: 132



View Profile
« Reply #10 on: January 24, 2009, 08:16:48 AM »

My fault, Pixel.

It should be ObjectCollide@ base NOT CollideObject... I edited my earlier post so its correct now.  Thats what happens when you script from memory (at work)  Embarrassed

You could also just use
Quote
object.GetCollideObject("Base").AddForce(Vector(x,y,z));
without messing with declaring a pointer at all.

Try it one more time, and if you still have problems I'd recommend looking at the the push_ball.gsl for the marble game.  It applies forces to the ball based on key-presses.  And it is much more stripped down compared to the character.gsl, so you should have an easier time seeing what's going on.
Logged
pixel_legolas
Hero Member
*****
Posts: 786


View Profile
« Reply #11 on: January 28, 2009, 04:16:10 AM »

hm, i think i got something to work. I was away this weekend so i tried it on a remote desktop so i couldnt see much what was happening Smiley

But i think what happened is it just made the character to spin.

The effect i am looking for is that when i make a attack i just want objects around me to fly away. I just want to make a outgoing force so boxes just start to fly away like an explosion Smiley AddForce only seemed to affect me.

Is it AreaForce i should use?
Logged
Ransom
Full Member
***
Posts: 132



View Profile
« Reply #12 on: January 28, 2009, 09:03:57 AM »

Yes.  Use...
Quote
GetGameManager().GetWorld().AddAreaForce(Vector(x,y,z));

Also, you'll want to temporarily turn off the collision for the player, so that he doesn't go flying too.
Logged
pixel_legolas
Hero Member
*****
Posts: 786


View Profile
« Reply #13 on: January 28, 2009, 09:24:47 AM »

thanks, will try that command and see what happens Smiley I'll get back to you
Logged
pixel_legolas
Hero Member
*****
Posts: 786


View Profile
« Reply #14 on: January 28, 2009, 02:40:35 PM »

Hm, i have tried so much but i get 2 errors at different times:

1. Unknown function 'Vector' and unknown function 'AddAreaForce'

when i write this line:

GetGameManager().GetWorld().GetObject("Player").AddAreaForce(vector(50,0,0));

2.  Unknown function 'Vector' and incorrect number of parameters for function AddAreaForce

when i write this line:

GetGameManager().GetWorld().AddAreaForce(vector(50,0,0));


It seems i can only use it in GetWorld and not after that. What is that vector thingy? If i just use AddAreaForce(x,y,z) i also get error.

I tried to declare a vector and used the example in character like this:

Vector camDir = cameraPos - object.GetCurMatrix().T;
GetGameManager().GetWorld().AddAreaForce(camDir);

And:

Vector camDir = cameraPos - object.GetCurMatrix().T;
            GetGameManager().GetWorld().AddAreaForce(camDir,0,0);


But whatever i do i get same errors. I just don't know what to do. I looked alot at character.gsl and push_ball.gsl

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!