Godot Version
4.5.1
Question
Hey is there an easy way to make one way collision for like a animal pen wall like slime rancher so you can shoot something in but then it cant get out itself? I dont know if im just missing it or what
4.5.1
Hey is there an easy way to make one way collision for like a animal pen wall like slime rancher so you can shoot something in but then it cant get out itself? I dont know if im just missing it or what
You can use an Area3D to detect the body from one side and then disable the collision shape.
here’s a simple code
func _on_body_entered(body: Node3D) -> void:
$wall/CollisionShape3D.disabled = true
So lets say I want to like let rigidbody3d and characterbody3d go in but not out id have that code snippit on like the outside area 3d then on inside one to turn it back on?
Edit: or would it be easier to just like turn it off for like a quarter of a second so its just enough for it to go in (How would i do that?)
you can’t touch the area3d once you are inside
I am having a little problem understanding what you want to explain.can you explain a little better?
so the code snippet you gave would turn off the walls collision but don’t i need like a check inside to turn it back on? Because if it stays off nothing is preventing the thing from just walking back out
Would it be easier to turn off the collision layer of whatever entered it then turn it back on once inside rather than disabling the walls collision itself
ohhh
well you can use another area3D inside to turn it on.Make sure to use body_exited because it may glitch
Got ya thanks ill try this in a bit once i get the chance
Ok i know im not doing it exactly right but this is what im thinking but i know im not declaring bodies right (I think)
extends Area3D
class_name PenGateStrip
func _on_body_entered(body: ItemPickup,friendlycritter) -> void:
$"../TestPen/wallf/StaticBody3D/CollisionShape3D".disabled = true
$"../TestPen/wallB/StaticBody3D/CollisionShape3D".disabled = true
$"../TestPen/wallR/StaticBody3D/CollisionShape3D".disabled = true
$"../TestPen/WallL/StaticBody3D/CollisionShape3D".disabled = true
how do i specify so it only does stuff if its in the “friendlycritter” or “Itempickup” group
EDIT: would this work?? there’s definitely a better way itempickup is rigidbody3d and critters are character body3d
func _on_body_entered(body) -> void:
if body == is_in_group("friendlycritter"):
$"../TestPen/wallf/StaticBody3D/CollisionShape3D".disabled = true
$"../TestPen/wallB/StaticBody3D/CollisionShape3D".disabled = true
$"../TestPen/wallR/StaticBody3D/CollisionShape3D".disabled = true
$"../TestPen/WallL/StaticBody3D/CollisionShape3D".disabled = true
if body == is_in_group("itempickup"):
$"../TestPen/wallf/StaticBody3D/CollisionShape3D".disabled = true
$"../TestPen/wallB/StaticBody3D/CollisionShape3D".disabled = true
$"../TestPen/wallR/StaticBody3D/CollisionShape3D".disabled = true
$"../TestPen/WallL/StaticBody3D/CollisionShape3D".disabled = true
it should be
body.is_in_group("Name")
ok good to knowwww
it’s the problem I think soo