-
-
Notifications
You must be signed in to change notification settings - Fork 498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add trigger direction property to script trigger #3041
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work. I'll test this soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The script only runs once with oneshot off.
Also it'd be cool if the editor drew a line that says which direction it's checking for, but this is just a suggestion.
Lots of people have been asking for this and im excited aswell!
9c17696
to
eb6dce0
Compare
I could not reproduce this.
Added that in the latest commit. |
I just found something: We could technically move the code to the trigger base class and support directions for all available triggers. |
Good idea |
const float indicator_width = 2.0f; | ||
const float indicator_length = 50.0f; | ||
std::vector<Rectf> indicators; | ||
|
||
Rectf left_indicator = Rectf(bbox.get_left() - indicator_length, | ||
bbox.get_middle().y - indicator_width, | ||
bbox.get_left(), | ||
bbox.get_middle().y + indicator_width); | ||
|
||
Rectf right_indicator = Rectf(bbox.get_right(), | ||
bbox.get_middle().y - indicator_width, | ||
bbox.get_right() + indicator_length, | ||
bbox.get_middle().y + indicator_width); | ||
|
||
Rectf up_indicator = Rectf(bbox.get_middle().x - indicator_width, | ||
bbox.get_top() - indicator_length, | ||
bbox.get_middle().x + indicator_width, | ||
bbox.get_top()); | ||
|
||
Rectf down_indicator = Rectf(bbox.get_middle().x - indicator_width, | ||
bbox.get_bottom(), | ||
bbox.get_middle().x + indicator_width, | ||
bbox.get_bottom() + indicator_length); | ||
|
||
if(m_trigger_direction == Direction::LEFT || m_trigger_direction == Direction::AUTO) | ||
indicators.push_back(left_indicator); | ||
if(m_trigger_direction == Direction::RIGHT || m_trigger_direction == Direction::AUTO) | ||
indicators.push_back(right_indicator); | ||
if(m_trigger_direction == Direction::UP || m_trigger_direction == Direction::AUTO) | ||
indicators.push_back(up_indicator); | ||
if(m_trigger_direction == Direction::DOWN || m_trigger_direction == Direction::AUTO) | ||
indicators.push_back(down_indicator); | ||
|
||
for(const auto& dir_indicator : indicators) | ||
{ | ||
context.color().draw_filled_rect(dir_indicator, color, transparency, layer); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't you just draw these rectangles directly? And you don't need to draw 4 indicators if a direction isn't specified, it's already implied.
|
||
context.color().draw_filled_rect(bbox, color, transparency, layer); | ||
|
||
if (!Editor::is_active() || m_trigger_direction == Direction::NONE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m_trigger_direction == Direction::NONE
is never true. Is it?
if (object_bbox.get_left() < bbox.get_left()) | ||
object_direction = Direction::LEFT; | ||
if (object_bbox.get_right() > bbox.get_right()) | ||
object_direction = Direction::RIGHT; | ||
if (object_bbox.get_top() < bbox.get_top()) | ||
object_direction = Direction::UP; | ||
if (object_bbox.get_bottom() > bbox.get_bottom()) | ||
object_direction = Direction::DOWN; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This algorithm doesn't look right. Is it possible to instead use the CollisionHit
given in collision
instead? You could save the direction to a member variable.
Adds a direction property to script trigger:
"auto" means that the trigger can be triggered from all sides.
"left" means only from the left side, "right" only from the right side etc.