Enemies not colliding with platform edges consistently

Just started using Construct 2? Post your questions here

Post » Wed Dec 07, 2016 10:28 pm

I'm not attaching a CAPX file to this message because I'm asking it on behalf of a student who is enrolled in my games class. (I teach at a liberal arts university in San Antonio, Texas.)

Her game is a simple platform game that follows the logic of the jungle platform tutorial. An invisible border box is attached to the skin for the player character, and that border box is used to detect collision with other objects. The platform behavior is also attached to the border box.

Enemies move from left to right, and they check for collision with an invisible edge sprite when they reach the end of their platforms. In this case, the enemies are just an animated sprite. They do not have an invisible box attached to them. As in the tutorial, an instance variable is used to keep track of the enemy's direction, and the enemies are flipped each time they collide with an invisible edge sprite.

Image

As the player moves through the game, the enemies suddenly start running off the platforms and falling to their deaths. It seems like it might be a collision detection problem. For some reason, it is more likely to happen when the enemies are outside of the viewport window. This is what the collision boundaries look like for the enemy sprite:

Image

I noticed that the fox sprite is *slightly* wider on certain frames than on other frames. (Never more than a couple pixels.)

Should we be using invisible border boxes with our enemy sprites to avoid this problem? If so, how would one do this with multiple enemy sprites? Would we need to have a unique invisible border box for each enemy sprite? That seems hugely unwieldy. Would we use UIDs to pin invisible border boxes to enemy sprites when the layout loads?

Thanks in advance for any help you might provide.
B
9
Posts: 16
Reputation: 363

Post » Wed Dec 07, 2016 11:00 pm

I avoid it by setting the same collision box for all the sprite animations in all animations, or by attaching a placeholder on the animation, while the placeholder is the real player.
Image
B
106
S
23
G
17
Posts: 1,356
Reputation: 22,135

Post » Wed Dec 07, 2016 11:04 pm

I'm not sure I know what you mean about the placeholder. Does the placeholder work for the *enemy* animations? Thanks!
B
9
Posts: 16
Reputation: 363

Post » Wed Dec 07, 2016 11:28 pm

Placeholder is an invisible sprite used pinned to the sprite animations, you can use it for everything and make all the real behaviors on it and leave the sprites to just animate against the events.

Some useful help can be read here:
https://www.scirra.com/tutorials/355/ma ... iple-parts
and here:
https://www.scirra.com/tutorials/361/un ... moke-trail
Image
B
106
S
23
G
17
Posts: 1,356
Reputation: 22,135

Post » Wed Dec 07, 2016 11:29 pm

Fantastic! I will look into this now. Thanks!
B
9
Posts: 16
Reputation: 363

Post » Thu Dec 08, 2016 6:58 pm

Message: adelwich can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
Thanks for the pointers, Gabriel!

In the rocket example that you shared, you dynamically added rockets into the game at random spawner locations. I am trying to implement this concept in a modified version of the default platform template.

I have multiple instances of a monster placeholder object (objEnemyBox), and I would like to pin monster skins (objMonsterSkin) to each of these at the beginning of the game. You can see what I've done in the attached CAPX file:

http://transmedia.trinity.edu/~adelwich/forum-images/dynamic-objects.capx

At the beginning of the layout, I'd like to attach skins to all of the objEnemyBoxes.

1) Do I need to dynamically add the monsters (objEnemyBox) through my event sheet when the game starts? Currently, I have just dragged them on to the layout where I want them.

2) If I need to add them dynamically, what is the best way to do this? Should I loop through each instance of a spawner object and place those objects where I want the enemies to exist?

Thank you for your help!
Aaron
B
9
Posts: 16
Reputation: 363

Post » Thu Dec 08, 2016 7:15 pm

I think I might have figured it out. When the layout starts, I use "for each instance of monsterPlaceholder" and dynamically pin the monster skin to the monster placeholder.

Image

This seems to work, but is this the recommended practice? Is there a better way of doing this? Are there times when my solution would be a very bad idea?
B
9
Posts: 16
Reputation: 363


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest