Simon keyboard movement with detect slopes!!!

  • #1, by TinTinMonday, 20. March 2017, 16:34 8 years ago
    Hi

    In some part of my game I only have control keyboard . I want disable 6 directions and only want left and right. Also Character detect slopes like this picture . Is it possible ? Or any tricks



    http://uupload.ir/files/0hsn_untitled-1.png " border="0" alt="" />

    Forum Fan

    196 Posts


  • #2, by afrlmeMonday, 20. March 2017, 16:38 8 years ago
    Instead of adjusting current position by x, you could just have it set destination position to width of screen for right & 0 for left. That way the character will automatically calculate position based on the way system, so if you have a path with it sloping then it should follow that - in theory.

    Imperator

    7285 Posts

  • #3, by TinTinMonday, 20. March 2017, 16:45 8 years ago
    Sorry I don't understand .How can I set position to width screen ? Would you mind any shot ?

    Forum Fan

    196 Posts

  • #4, by afrlmeMonday, 20. March 2017, 17:09 8 years ago
    You could create a global Lua variable to store the scene width inside of & use getSize() function inside of an at begin of scene action to update the variable with the current scenes width & height or you could create a Lua table & manually enter the scene sizes into that - latter being more work but less taxing on system resources (Simon mentioned to me ages ago that getSize is a slow function or something - I forget exactly what he said as it was quite a while back).
    scnxy = game.CurrentScene.SceneSprite.SpriteSprite:getSize() -- create a table containing x, y (width & height of current scene)


    -- key pressed right right arrow / d
    game.CurrentCharacter.CharacterDestination = {x = scnxy.x, y = game.CurrentCharacter.CharacterPosition.y}


    alternatively, you could use Lua tables... ("scene1" etc. should be replaced with actual scene names)
    scn_data = {}
    scn_data["scene1"] = {width = 1920, height = 1080}
    scn_data["scene2"] = {width = 1920, height = 1320}


    game.CurrentCharacter.CharacterDestination = {x = scn_data[game.CurrentScene:getName()].width, y = game.CurrentCharacter.CharacterPosition.y}


    Quick note: not sure if either of these examples are correct. Been a while since I used getSize() & I've written these from memory & based on what I see on scripting/data structure pages of the wiki.

    Imperator

    7285 Posts

  • #5, by TinTinMonday, 20. March 2017, 18:54 8 years ago
    Thanks a lot . I'll try it . If I had question let you know .

    Forum Fan

    196 Posts

  • #6, by TinTinTuesday, 21. March 2017, 07:29 8 years ago
    I don't success yet . I used Simon keyboard movement . Can you help me how can I optimize it for slopes with your codes?
    Maybe I'm wrong because I'm not good programmer

    Forum Fan

    196 Posts

  • #7, by sebastianTuesday, 21. March 2017, 08:20 8 years ago
    I guess Lee posted a script which let the character go automatically after key press. Because the character will try to walk inside the waysystem, he will go with the slopes if waypoints are set. 

    whats needed here is a script which adds/substracts some pixels from the characters current x location and set it as his new destination coordinates. If the destination location is outside the waysystem polygon (by reaching a way systems border / a slope)  you have to decide if the chars y coordinate of the destination has also be rised or reduced to let him walk up or down a bit, too. The main problem here is that you don't know if you have to go up  or down... don't know how to solve this, though... and because of this i can't really give a script to test. 

    Thread Captain

    2346 Posts

  • #8, by afrlmeTuesday, 21. March 2017, 11:10 8 years ago
    If the paths are stricted & few, it should auto follow it. I suppose one thing that could be done is to use action areas. If the character enters from left (aligned right) or from right (aligned left) then you could update the y destination position based on that.

    This would be much easier with something like Game Maker Studio because it's specifically designed for platformer games & allows you to draw masks on tiles & determine if they are slopes/hills & assign gravity values to them - far as I can remember (been a while since I last looked at it).

    Imperator

    7285 Posts