PDA

View Full Version : Please Help (Jumping)



kehran
06-11-2011, 09:16 AM
Hi, im trying to get my character to jump, as of now it can move left and right no problem xD (its a scroller game). But when i add the jump code or what i think is the jump code nothing happens, it doesn't budge.

here is the player.lua code




RunScript("system/player_utils.lua"); //has some useful global functions, this is in base

function OnInit() //run upon initialization

this:GetBrainManager():Add("StandardBase","");

//hint to the path-finding system that it can ignore this while computing paths if it needs to
this:SetIsCreature(true);

this:SetVisualProfile("MainCharacterAI/MainCharacterAI.xml", "MainCharacterAI");

//limit movement to horizontal only
this:GetBrainManager():SendToBrainBase("control_filtery=0");
end


function OnPostInit() //run after being placed on a map

this:SetName("Player")

//Note: the "always" keyword means the key will always react, regardless of what else is
//also pressed. Without it, you couldn't shoot and walk at the same time


GetInputManager:AddBinding("left,always", "OnLeft", this:GetID());
GetInputManager:AddBinding("right,always", "OnRight", this:GetID());
GetInputManager:AddBinding("up,always", "OnUp", this:GetID());

ResetKeys(); //our function to reset our local key input vars

//let's have a function that gets run every logic tick
this:SetRunUpdateEveryFrame(true);
end


function OnKill() //run when removed
RemoveActivePlayerIfNeeded(this); //let the engine know we shouldn't be the active player any more
end

function Update(step)

AssignPlayerToCameraIfNeeded(this); //make us the official player and have the camera track us,
//if we're not already, and if another entity doesn't already have this role

//this function is in player_utils.lua
local facing = ConvertKeysToFacing(m_bLeft, m_bRight, m_bUp, m_bDown);

if (facing != C_FACING_NONE) then
//they are pressing towards a direction
this:SetFacingTarget(facing); //turn towards the direction of the keys we pressed
this:GetBrainManager():SetStateByName("Walk");
else
this:GetBrainManager():SetStateByName("Idle");
end

if( m_bUp ) then
if (this:GetOnGround()) then
this:StopY(); //Kill any Y interia so each jump is exactly the same height, feels more consistant
this:StopX();
this:AddForceConstant(Vector2(0, -250))
end
end
end



function ResetKeys()

m_bLeft = false;
m_bRight = false;
m_bUp = false
end

function OnLeft(bKeyDown)
m_bLeft = bKeyDown;
return true; //continue to process key callbacks for this key stroke
end

function OnRight(bKeyDown)
m_bRight = bKeyDown;
return true; //continue to process key callbacks for this key stroke
end

function OnUp(bKeyDown)
m_bUp = bKeyDown;
return true; //continue to process key callbacks for this key stroke
end

Tathagat Singh
06-25-2011, 06:45 AM
Try merging it with Treeworld example, there is a neat jump code there. and let me know if you need any help with the engine, its 2007 since it was last updated and i wanna revive it, but i need help.