Jump to content


Photo

Make sprites (not objects) solid


  • Please log in to reply
5 replies to this topic

#1 interpolicer

interpolicer

    GMC Member

  • GMC Member
  • 149 posts
  • Version:GM8.1

Posted 23 November 2011 - 11:14 AM

Howdy.

See this:
Posted Image
(yes, Reiner's graphics)

I have tuned (finally) my main character (the ninja), making him walk in all 8 directions, full with lots of animations to equip/unequip, throw shuriken, walk, run, attack...

But now here's the thing:
I want to populate my game world and start making my adventure, and I planted those trees there but I remembered that there's no way to tell my main character to stop on collision with the trees. Will I have to create an invisible object so that my char stops on collision, or is there a better way to do it in code?

Adding invisible objects would probably work, but would be tiresome, and adding a tree as an object would make my boy stop on hittins the leafs...

Any suggestion? :)
  • 0

#2 Noele

Noele

    GMC Mentor

  • GMC Member
  • 3406 posts
  • Version:GM:Studio

Posted 23 November 2011 - 12:22 PM

I am assuming your trees are from a tile set, in which case they will have no collision properties. Checking for a collision with a tile with large characters would be tiresome and simpler to use an object. One point to note is tiles are background images and by default the tile layer will be behind all objects in the room, meaning the characters would be able to walk all over them.

Placing an invisible object over the top would allow you to check for and avoid a collision however no part of your character's collision mask would be able to touch the tree - it would not be able to walk in front or go behind it.

Conventionally the technique here is to create a tree object but alter its collision mask so that only the bottom section of the tree trunk is used and set its Y origin near to the bottom. In its Create Event you set its depth relative to its Y position in the room and set all movable objects to the same in their Step Events. It all sounds more complex than it is:

Here is the "magical" code:
Execute Code:
depth = -y;

The player character depth will change proportionate to where it is in the room enabling it to appear in front of or behind objects (like trees).

Check out the tutorials forum about adding depth.
  • 0

#3 interpolicer

interpolicer

    GMC Member

  • GMC Member
  • 149 posts
  • Version:GM8.1

Posted 23 November 2011 - 03:50 PM

I am assuming your trees are from a tile set, in which case they will have no collision properties. Checking for a collision with a tile with large characters would be tiresome and simpler to use an object. One point to note is tiles are background images and by default the tile layer will be behind all objects in the room, meaning the characters would be able to walk all over them.

Placing an invisible object over the top would allow you to check for and avoid a collision however no part of your character's collision mask would be able to touch the tree - it would not be able to walk in front or go behind it.

Conventionally the technique here is to create a tree object but alter its collision mask so that only the bottom section of the tree trunk is used and set its Y origin near to the bottom. In its Create Event you set its depth relative to its Y position in the room and set all movable objects to the same in their Step Events. It all sounds more complex than it is:

Here is the "magical" code:
Execute Code:

depth = -y;

The player character depth will change proportionate to where it is in the room enabling it to appear in front of or behind objects (like trees).

Check out the tutorials forum about adding depth.

:smile::)
You answered another question I was going to pose about backgrounds and their depth. I'm using Tile Layers in the room editor, and found out that no mater what I do, my character walks over everything.

Could I make a tree object and add:
depth = -bbox_bottom
Like my troll and character have? I find your solution very gracious, though. I already see it working if I use "pushable" objects in the future.

I didn't remember about the collision mask. Thanks for reviving my memory (weeks without GM make this). :chikin
  • 0

#4 Noele

Noele

    GMC Mentor

  • GMC Member
  • 3406 posts
  • Version:GM:Studio

Posted 23 November 2011 - 04:00 PM

Could I make a tree object and add:

depth = -bbox_bottom

You could but that will only set it to the bottom of the bounding box for that sprite. To make it so the character can walk in front and go behind, its depth must be proportional to its Y position in the room. You could however set the depth to -y + its sprite height:
depth = -(y+100);

  • 0

#5 interpolicer

interpolicer

    GMC Member

  • GMC Member
  • 149 posts
  • Version:GM8.1

Posted 23 November 2011 - 05:19 PM

I am yet to insert the collisions with my character, but if I implement the same approach to my character (using manual collision masks), I think I'll have trouble later when I try to implement collisions with flying objects, for instance?
I see this working when touching the trees, fences or something, but what about projectiles?

Changing collision masks with code is viable?
  • 0

#6 Noele

Noele

    GMC Mentor

  • GMC Member
  • 3406 posts
  • Version:GM:Studio

Posted 23 November 2011 - 05:28 PM

Oh yes indeed! You can swap sprite images anytime. You can duplicate a sprite and modify its collision mask or tell it to use a different collision mask sprite to the one it displays.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users