Skip to content
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 character #6

Merged
merged 2 commits into from
Dec 27, 2023
Merged

add character #6

merged 2 commits into from
Dec 27, 2023

Conversation

lain-dono
Copy link
Member

Добавил примитивную реализацию персонажей

Comment on lines +46 to +48
ctrl.velocity = match ctrl.target {
Some(target) => (target - transform.translation).normalize_or_zero() * ctrl.speed,
None => Vec3::ZERO,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

призрачный гонщик через стены без алгоритма

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Потом вместо этого будет навмеш и прочие ништяки. Мб реализация навмешей будет через https://github.com/TheGrimsey/oxidized_navigation, с меньшей вероятностью через https://github.com/vleue/bevy_pathmesh

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кстати, поскольку все персонажи будут так или иначе использовать navmesh, то работы с коллизиями почти не будет (не уверен, нужна ли нам физика вообще).

Comment on lines +41 to +56
pub fn move_character(
time: Res<Time>,
mut query: Query<(&mut CharacterController, &mut Transform), Without<Parent>>,
) {
for (mut ctrl, mut transform) in query.iter_mut() {
ctrl.velocity = match ctrl.target {
Some(target) => (target - transform.translation).normalize_or_zero() * ctrl.speed,
None => Vec3::ZERO,
};
transform.translation += ctrl.velocity * time.delta_seconds();

if ctrl.velocity.length() > 0.0 {
// TODO: remove pitch/roll
*transform = transform.looking_to(ctrl.velocity, Vec3::Y);
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В идеальном случае нужно сократить количество вызовов и не делать всё это каждый кадр.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

добавь TODO

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут всё максимально быстро работает, не вижу причин для оптимизаций. С другой стороны таргет можно хоть каждый кадр менять (например оный может двигаться).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В целом это всё лишь затычка для текущего уровня технологий. Но поверх этого уже можно делать AI например.

@komunre komunre merged commit e96a54d into main Dec 27, 2023
2 of 3 checks passed
@lain-dono lain-dono deleted the character branch January 4, 2024 02:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants