Results 1 to 5 of 5

Thread: Don't Stop!

  1. #1
    Lesser Wizard
    Join Date
    Mar 2008
    Posts
    124

    Default Don't Stop!

    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.

  2. #2
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,377

    Default

    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):


    Code:
    	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..)

    Code:
    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
    Seth A. Robinson
    Robinson Technologies

  3. #3
    Lesser Wizard
    Join Date
    Mar 2008
    Posts
    124

    Default

    Thanks for that. I shall give it a try later.

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

  4. #4
    Lesser Wizard
    Join Date
    Mar 2008
    Posts
    124

    Default

    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!

  5. #5
    Lesser Wizard
    Join Date
    Mar 2008
    Posts
    124

    Default

    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)

Similar Threads

  1. Dink Won't Stop!!!
    By dawn in forum Dink Smallwood HD
    Replies: 2
    Last Post: 11-21-2006, 04:18 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •