PDA

View Full Version : Don't Stop!



Pleng
03-13-2008, 09:30 PM
Hi guys

Firstly I'd like to say a great big THANK YOU for Novashell. It seems to be, from what I can see, the most powerful & versatile cames creation system around that's actually easy to pick up and use!

I've had great fun playing around with the Tree Demo and am creating a new project based on it.

What I need to do, though, is make it so that the player won't stop moving until another direction is selected, or he hits a wall.

Ie player starts off on the map standing still, but after the player presses right he will continue to move right unless he comes to a wall, or the player presses left. The same to be true when the player is moving left.

My limited scripting experience leads me to believe I need to be doing something with the OnLeft(bKeyDown) and OnRight(bKeyDown) functions in ent_player.lua, but I simply can't figure out exactly what I have to do.

Any help would be greatly appreciated.

Seth
03-14-2008, 10:04 AM
Thanks for the encouragement!


What I need to do, though, is make it so that the player won't stop moving until another direction is selected, or he hits a wall.

This is a pretty easy change - first, make it so the player won't stop when a key isn't being pushed.

In ent_player.lua, find the following snippet in the function ProcessMovement(step):



this:GetBrainManager():SetStateByName("Walk");
m_lastDirection = facing; //store this for ladder, like when we get off the ladder
else
this:GetBrainManager():SetStateByName("Idle");
end

And comment out/remove the line this:GetBrainManager():SetStateByName("Idle");.

Now the player will never stop.

To make it so he'll stop when a wall is hit you need to make a few smallish changes to the OnCollisionStatic function. For simplicity, just replace the one you have with this new one: (compare them to see what I did..)



function OnCollisionStatic(normal, depth, materialID)

if (m_bOnLadder) then
return false; //while on ladders let's ignore static collisions
end

//LogMsg("Hit Static: Depth: " .. tostring(depth) .. " normal: " .. tostring(normal));

if (normal.y > 0.8 and depth > 0.01) then

//They hit their head on a static wall
if (m_jumpSfxTimer < GetApp:GetGameTick()) then
GetSoundManager:Play("audio/mario/bump.wav");
//Set timer so we won't play it again too soon
m_jumpSfxTimer = GetApp:GetGameTick() + m_jumpSfxMinTimeBetweenSoundsMS;
end
else
//well, we know they didn't bump their head.
//let's filter out the normal floor collision so we can see when they hit a wall
if (normal.y > -0.8) then
this:GetBrainManager():SetStateByName("Idle");
end

end

return true;
end

Pleng
03-14-2008, 10:25 AM
Thanks for that. I shall give it a try later.

Right now I'm working my way through the Dragon Egg tutorial :)

Pleng
03-14-2008, 12:02 PM
Ok that worked brilliantly, thanks.

The only problem I now have is that there appears to be some acceleration/deceleration built in to the control logic? I need to have my hero always moving at top speed.

ie if he is walking left and the player presses right, he will instantly turn around and run in the opposite direction at the same speed he was originally going.

Is this possible?

Thanks again for all your help! :)

Pleng
03-15-2008, 09:11 AM
Problem solved. For reference, if anybody is searching the form and has the same issue, the following line needs to be added to function SetDeafaults:

this:SetAcceleration(10)