Interacting with the player class - how?
by Steven Peterson · in Torque Game Engine · 11/13/2005 (6:01 pm) · 11 replies
I'm trying to do several things that seem simple but I can't figure out how:
1) in default.bind.cs I want to call %client.Player.myNewPlayerFunction(); and bind it to a button. However I don't have %client. How do I get it?
2) How do I get values like "currentPlayerVelocity", and "currentGroundSlopeUnderPlayer" etc? They have to exist somewhere but can't seem to find them. I want to use them in scripts like in Player::myNewPlayerFunction(%this) or even in default.bind.cs
3) How can I check if the player is colliding with a wall (terrain or .dif) to the right, left or in front? Since the player is in a collision box, I imagine this is easy to check, but don't know how.
I'm sure SOME of these are in the Docs but a quick search didn't turn up quick answers - so a link is appreciated if your tempted to answer RTFM ;-)
Thanks,
Raven
1) in default.bind.cs I want to call %client.Player.myNewPlayerFunction(); and bind it to a button. However I don't have %client. How do I get it?
2) How do I get values like "currentPlayerVelocity", and "currentGroundSlopeUnderPlayer" etc? They have to exist somewhere but can't seem to find them. I want to use them in scripts like in Player::myNewPlayerFunction(%this) or even in default.bind.cs
3) How can I check if the player is colliding with a wall (terrain or .dif) to the right, left or in front? Since the player is in a collision box, I imagine this is easy to check, but don't know how.
I'm sure SOME of these are in the Docs but a quick search didn't turn up quick answers - so a link is appreciated if your tempted to answer RTFM ;-)
Thanks,
Raven
#2
It did work, but it didn't get me what i expected unfortunetly, so i'm still stuck. One of the things I want to be able to do is override some of the playerBody values for an effect while the buttons held down, and then change it back. One example might be "runSurfaceAngle".
I thought since the datablock deffinition is right there, I could get at the variables too. Now i'm not so sure.
11/13/2005 (10:57 pm)
Thanks Ramen. Sounds like good ideas though I've only tried the first one so far. It did work, but it didn't get me what i expected unfortunetly, so i'm still stuck. One of the things I want to be able to do is override some of the playerBody values for an effect while the buttons held down, and then change it back. One example might be "runSurfaceAngle".
I thought since the datablock deffinition is right there, I could get at the variables too. Now i'm not so sure.
#3
if you do... %player.getDatablock() it'll point to that datablock, from there, trying doing a dump of the datablock and see if any info you need is there. Could be cake if your player has a datablock ONLY for the player.
11/14/2005 (3:29 am)
Oh, i see. From what i gather.... it's not easy to change datablock values, cause when you change a datablock value, it changes it for all objects using that datablock.if you do... %player.getDatablock() it'll point to that datablock, from there, trying doing a dump of the datablock and see if any info you need is there. Could be cake if your player has a datablock ONLY for the player.
#4
I would think the datablock values become members of each individual instance of the class, and so could be changed for each instance separately but who know...
I'm not doing multi-player so whatever, we'll just make it work :-P
11/14/2005 (6:54 am)
I'll give that a try, I guess there will only be one "Player", no idea how NPC's and monsters are handeled yet, thats like next-month lol...I would think the datablock values become members of each individual instance of the class, and so could be changed for each instance separately but who know...
I'm not doing multi-player so whatever, we'll just make it work :-P
#5
11/14/2005 (7:11 am)
Only 1/2 worked... I might need to find where my values are used in the engine and create hooks to them. Here's the broken code... function Player::startWallRun(%this)
{
%player* = %this.getDatablock();
// BookKeeping
echo("Start Wall Run - Client: " @ %this @ " Player: " @ %player);
%player.wallRun = 1; // We are in fact wall running
$wallRunSched = schedule(3000,0, "Player::stopWallRun", $myPlayer);
// PlayerChanges
echo("Old Angle: " @ %player.runSurfaceAngle);
%player.oldRunSufaceAngle = %player.runSurfaceAngle;
%player.runSurfaceAngle = 90;
echo("New Angle: " @ %player.runSurfaceAngle);
}
function Player::stopWallRun(%this)
{
%player = %this.getDatablock();
if (%player.wallRun)
{
// BookKeeping
echo("Stop Wall Run - Client: " @ %this @ " Player: " @ %player);
%player.wallRun = 0;
cancel($wallRunSched);
// PlayerChanges
echo("Old Angle: " @ %player.runSurfaceAngle);
echo("New Angle: " @ %player.oldRunSurfaceAngle);
%player.runSurfaceAngle = %player.oldRunSurfaceAngle;
}
}
#6
%player* = %this.getDatablock();
you got an astrisk there for some reason like you're creating a pointer in C++
So you're trying to get a player to walk on the wall? that's gonna be hard. you can't just turn them sideways anyhow. least it's not easy. adjusting the datablock values do work, like try adjusting maxforwoardspeed or maxstepheight, those work just as they should... but that runsurface angle doesn't seem to do anything when i adjust it.
11/14/2005 (7:18 pm)
What's up with this???%player* = %this.getDatablock();
you got an astrisk there for some reason like you're creating a pointer in C++
So you're trying to get a player to walk on the wall? that's gonna be hard. you can't just turn them sideways anyhow. least it's not easy. adjusting the datablock values do work, like try adjusting maxforwoardspeed or maxstepheight, those work just as they should... but that runsurface angle doesn't seem to do anything when i adjust it.
#7
I'm trying another approach, so I'll report back with what happens.
Yeah - want to walk on walls. It's just a proof-of-concept test at this point but I think the rotation should be largely done by rotateing the players position. I guess i'll find out soon.
Thanks!
11/15/2005 (10:18 pm)
The first time I tried it I got the impression it was copying the datablock to %player. So I never changed the original datablock. Then I did try creating a pointer to point to the original, and that didn't work either. Guess i forgot the * when I took it back out. I'm trying another approach, so I'll report back with what happens.
Yeah - want to walk on walls. It's just a proof-of-concept test at this point but I think the rotation should be largely done by rotateing the players position. I guess i'll find out soon.
Thanks!
#8
11/15/2005 (10:47 pm)
There was a post not too long ago on wall walking.... might wanna search for it and see what results came of it.
#9
@All - To this end i've tried adding some new ConsoleMethods to PlayerData:
I get this wonderfully uninformative error msg. from the VC6 compiler.
Say What?! Where'd I go wrong?
11/15/2005 (11:25 pm)
@Ramen - kk, thanks!@All - To this end i've tried adding some new ConsoleMethods to PlayerData:
ConsoleMethod( PlayerData, setRunSurfaceAngle, void, 3, 3, "(F32")
{
object->setRunSurfaceAngle(dAtof(argv[2]));
}
ConsoleMethod( PlayerData, getRunSurfaceAngle, F32, 2, 2, "Return the max slope to run up.")
{
return object->getRunSurfaceAngle();
}
F32 PlayerData::getRunSurfaceAngle()
{
return runSurfaceAngle;
}
void PlayerData::setRunSurfaceAngle(F32 angle)
{
runSurfaceAngle = angle;
}I get this wonderfully uninformative error msg. from the VC6 compiler.
Quote:Linking...
player.obj : error LNK2001: unresolved external symbol "public: static void __cdecl PlayerData::consoleInit(void)" (?consoleInit@PlayerData@@SAXXZ)
../Zelda/tLOZ.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Creating browse info file...
tLOZ.exe - 2 error(s), 0 warning(s)
Say What?! Where'd I go wrong?
#10
11/15/2005 (11:35 pm)
I don't believe you need to be using the playerdata class.... all the other console methods are for Player, not playerdata.
#11
the variable I want though, is a member of playerData not player right?
This consoleMethod stuff has me throughly confused so I could be way off...
11/15/2005 (11:51 pm)
Hmmm. i just found my link error - that was a tuff one. was initilizing somthing in the wrong place i guess...the variable I want though, is a member of playerData not player right?
This consoleMethod stuff has me throughly confused so I could be way off...
Torque Owner Cinder Games
2) .getVelocity() is a method for you can use to get velocity.
3) onCollsion, you can probably send out a ray cast to the left and right and figure out which side you hit on.