Trouble with Mario style [ ? ] Box.

Hi all,

BoxIssue.png

In the Super Mario Bros. series of games, as well as a few other platformers on the market, the player can make their character jump and hit a box or other square object that causes something to happen or an item to appear.  This is the effect I am trying to do and yet having trouble with.

ISSUES:

  • I can make my character 'jump' to the box, but I don't want him showing the jumping curve animation.  Instead, I'd rather my character just go straight up and down and not do the jumping curve.
  • If I change it instead to 'move up' 'move down' rather than the 'jump', he doesn't move because of the impassible tile between him and the box.
  • When the player touches the box, the box's event does not activate, despite the box having a player touch event.
Please keep in mind that I do not have an actual jumping system.  Rather, I have an invisible 'action key' event placed 2 squares below, where the player must be on the square and be pressing the key for him to jump.

And, as always, any and all help is greatly appreciated.
What "jumping curve"? If your x and y are both 0, there should be no curve.


The box probably doesn't activate because the whole jump - up AND down - is the movement, and events are only triggered at the end of a movement.


What is the trigger of your event - Player Touch, or Event Touch? Can you show a screenshot of your box event? Include the whole window, not just the commands.
Ah!  I didn't know about setting them both X & Y to 0.  That does what I want in that regard.

Oh and by jumping curve lets see.  When the character jumps and they hop off the one tile and then to the other, it always looks different to me than them just jumping up and down.  It ends up looking like a bit of a curve, or arc if you will to my eyes.

And

Here are the screenshots for the box itself that still don't work.

BoxEvent_Page1.jpgBoxEvent_Page2.jpg

I haven't added anything else to the box other than to turn the self switch on because I want to make sure it will do at least that before adding other stuff to it.
 
Yeah, this is actually pretty complicated (unless I'm overlooking something obvious).

For starters, the player hits the box in the middle of the movement, but events don't trigger until a movement has ended.

Secondly, the coordinates used to check for a collision is the 32x32 tile at the BASE of the sprite, so even if the event DID trigger, the player's FEET would have to hit it in order to make it happen.

Thirdly, when the character jumps, it doesn't actually jump a full tile, so the x and y coordinate of the player will actually not change.

You have to use screen coordinates, and compare the base of the box with the head of the player, which involves a bit of maths.

Let me see if I can get a little script done up to make this work ...

Edit: alright, here you go. Put this script into its own slot at the bottom of all your other custom scripts:

class Game_CharacterBase def width sign = @character_name[/^[\$]./] if sign && sign.include?('$') w = Cache.character(@character_name).width / 3 else w = Cache.character(@character_name).width / 12 end return w end def height sign = @character_name[/^[\$]./] if sign && sign.include?('$') h = Cache.character(@character_name).height / 4 else h = Cache.character(@character_name).height / 8 end return h end def touching(character) # get bounding box for self and other me = Rect.new(screen_x + 16 - width / 2, screen_y + 32 - height, width, height) them = Rect.new(character.screen_x + 16 - character.width / 2, character.screen_y + 32 - character.height, character.width, character.height) # do they overlap? return me.x < (them.x + them.width) && (me.x + me.width) > them.x && me.y < (them.y + them.height) && (me.y + me.height) > them.y endendclass Game_Interpreter alias shaz_mariojump_game_interpreter_setup setup def setup(list, event_id = 0) shaz_mariojump_game_interpreter_setup(list, event_id) @event = $game_map.events[@event_id] if event_id > 0 endendNow, change your event's first page to be triggered by Parallel Process, and add these event commands:
Code:
Conditional Branch: Script: $game_player.x == @event.x && $game_player.y > @event.y && $game_player.jumping? && @event.touching($game_player)  # do stuffBranch EndWait 1 Frame
The wait 1 frame is so, if you have a dozen of these on the same map, they're not going to make it lag.Now, in the # do stuff, you need to consider that this condition will be true maybe 8-10 times during a jump, so if it's giving money or playing an SE, it will do it several times. So you want to do something after the first time to make sure it doesn't keep doing it (like turn on a self switch, as you've got there already).
Wow!  Thanks so much for that.  It worked!  I really appreciate it 😀 .
This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/trouble-with-mario-style-box.21683/