Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Cooperative Cuisine Environment
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Social Cognitive Systems
CoCoSy
Cooperative Cuisine Environment
Commits
3f3344c3
Commit
3f3344c3
authored
1 year ago
by
Fabian Heinrich
Browse files
Options
Downloads
Patches
Plain Diff
Added collision detectio for player with players and player with counters
parent
fc53aeaa
No related branches found
No related tags found
1 merge request
!2
Resolve "2D movement continuous"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
overcooked_simulator/overcooked_environment.py
+50
-1
50 additions, 1 deletion
overcooked_simulator/overcooked_environment.py
overcooked_simulator/player.py
+1
-0
1 addition, 0 deletions
overcooked_simulator/player.py
with
51 additions
and
1 deletion
overcooked_simulator/overcooked_environment.py
+
50
−
1
View file @
3f3344c3
...
...
@@ -143,9 +143,58 @@ class Environment:
player: The player for which to check collisions.
Returns: True if the player is intersecting with any object in the environment.
"""
return
self
.
detect_player_collision
(
player
)
or
self
.
detect_collision_counters
(
player
)
def
detect_player_collision
(
self
,
player
:
Player
):
"""
Detects collisions between the queried player and other players.
A player is modelled as a circle. Collision is detected if the distance between the players is smaller
than the sum of the radius
'
s.
Args:
player: The player to check collisions with other players for.
Returns: True if the player collides with other players, False if not.
"""
pass
other_players
=
filter
(
lambda
p
:
p
.
name
!=
player
.
name
,
self
.
players
.
values
())
def
collide
(
p
):
return
np
.
linalg
.
norm
(
player
.
pos
-
p
.
pos
)
<=
(
player
.
radius
+
p
.
radius
)
return
any
(
map
(
collide
,
other_players
))
def
detect_collision_counters
(
self
,
player
:
Player
):
"""
Checks for collisions of the queried player with each counter.
Args:
player: The player to check collisions with counters for.
Returns: True if the player collides with any counter, False if not.
"""
return
any
(
map
(
lambda
counter
:
self
.
detect_collision_player_counter
(
player
,
counter
),
self
.
counters
))
def
detect_collision_player_counter
(
self
,
player
:
Player
,
counter
:
Counter
):
"""
Checks if the player and counter collide (overlap).
A counter is modelled as a rectangle (square actually), a player is modelled as a circle.
The distance of the player position (circle center) and the counter rectangle is calculated, if it is
smaller than the player radius, a collision is detected.
TODO: Efficiency improvement by checking only nearest counters? Quadtree...?
Args:
player: The player to check the collision for.
counter: The counter to check the collision for.
Returns: True if player and counter overlap, False if not.
"""
size
=
self
.
counter_side_length
cx
,
cy
=
player
.
pos
dx
=
max
(
np
.
abs
(
cx
-
counter
.
pos
[
0
])
-
size
/
2
,
0
)
dy
=
max
(
np
.
abs
(
cy
-
counter
.
pos
[
1
])
-
size
/
2
,
0
)
distance
=
np
.
linalg
.
norm
([
dx
,
dy
])
return
distance
<
player
.
radius
def
step
(
self
):
"""
Performs a step of the environment. Affects time based events such as cooking or cutting things, orders
...
...
This diff is collapsed.
Click to expand it.
overcooked_simulator/player.py
+
1
−
0
View file @
3f3344c3
...
...
@@ -13,6 +13,7 @@ class Player:
self
.
pos
=
np
.
array
(
pos
,
dtype
=
float
)
self
.
holding
=
None
self
.
radius
=
18
self
.
move_dist
=
5
self
.
interaction_range
=
50
self
.
facing_direction
=
np
.
array
([
0
,
1
])
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment