- Home /
How do I create a partial 2D sprite collision during trigger?
I have a sprite that is attach to the camera and it is one the mid-ground layer. The player is a 2D sprite with a collider that moves forwards and backwards, and it can collide with objects in its path. The enemy/sprite collider is to trigger and hit or block the path of the player, preventing it from moving or killing it. My problem is that the player is on the foreground and the enemy is visible but not meant to block the path until trigger. I currently stuck on how to implement this. Any help would be great.
I don't quite understand. The enemy is supposed to block the player when he was triggered? By whom? By the player? If so, why not blocking him in the first place, what's the difference with triggering? Could you explain a bit better?
Background, $$anonymous$$idground, Foreground
$$anonymous$$idground has the enemy sprite idle until a certain trigger occurs
Player is in Foreground moving along like a 2D scroller
When player hits object it activates the trigger
Enemy attacks but only a portion of it is to hit the player or block its path *Would it be possible to make a partial collider or only have a portion of the enemy sprite be the collider?
Yes, add one to the enemy and adjust it's dimensions and position on it. Or create a child gameobject, add a Collider to that and position and scale it accordingly
Answer by Mercbaker · Jul 02, 2017 at 12:54 AM
There's no such thing as a "partial" collision, it either collides or doesn't.
What you probably want to do is when the player collides with the enemy you call a function on the player to reduce its speed or reduce some stat over time(start a timer).
Or if the player moves closer to the enemy.position then you track that position data. As the player gets closer to the enemy then you increase the effect based off of the position.
In other words. When the player collides with a trigger, call a function and create a unit of measure that changes > update variables based off of those changes.
Your answer
Follow this Question
Related Questions
using IsTouchingLayer without collision 0 Answers
Ignore Collision for 2d Collider 2 Answers
Detecting collision of two game objects? 0 Answers
Sometimes my character falls through the ground? 1 Answer
Compound collision! 1 Answer