|
pixel_legolas
|
 |
« 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: if (params.stringValue == "die") { diePressed = params.floatValue; return true; } What i tried was adding this line: 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" 
|
|
|
|
|
Logged
|
|
|
|
|
Ron
|
 |
« 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 float spoilerForce = speed * 125.0f; collideBase.AddForce( -mtx.YAxis * spoilerForce); if (spoilerForce >= 0) { body.AddForce( object.GetCurMatrix().Project( 0, -spoilerForce, 0)); }
|
|
|
|
|
Logged
|
|
|
|
|
Ron
|
 |
« Reply #2 on: January 22, 2009, 02:45:17 PM » |
|
Here is another example (simpler) that may help Vector Pos = object.GetPosition(); object.AddForce( Vector( Pos.x/1.5, 0, -Pos.z/1.5));
|
|
|
|
|
Logged
|
|
|
|
|
Squat
|
 |
« Reply #3 on: January 22, 2009, 03:02:00 PM » |
|
Taken right out of Destructable.gsl object.GetWorld().AddAreaForce( hitPosition, explodeRange, explodeForce);
|
|
|
|
|
Logged
|
|
|
|
|
Ransom
|
 |
« 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... 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... base.AddForce(ForceX,ForceY,ForceZ);
|
|
|
|
|
Logged
|
|
|
|
|
pixel_legolas
|
 |
« 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: 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
|
 |
« Reply #6 on: January 23, 2009, 02:17:32 PM » |
|
I'm sorry, you need to tell the engine your using a vector. Use... 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... //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
|
 |
« 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
|
 |
« 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
|
 |
« 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 
|
|
|
|
|
Logged
|
|
|
|
|
Ransom
|
 |
« 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)  You could also just use 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
|
 |
« 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  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  AddForce only seemed to affect me. Is it AreaForce i should use?
|
|
|
|
|
Logged
|
|
|
|
|
Ransom
|
 |
« Reply #12 on: January 28, 2009, 09:03:57 AM » |
|
Yes. Use... 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
|
 |
« Reply #13 on: January 28, 2009, 09:24:47 AM » |
|
thanks, will try that command and see what happens  I'll get back to you
|
|
|
|
|
Logged
|
|
|
|
|
pixel_legolas
|
 |
« 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
|
|
|
|
|