adding physics object statue
This commit is contained in:
		
							
								
								
									
										27
									
								
								PhysicsObjects/HandStatue/HandStatue.gd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								PhysicsObjects/HandStatue/HandStatue.gd
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,27 @@
 | 
			
		||||
extends RigidBody2D
 | 
			
		||||
 | 
			
		||||
@onready var rigid_body = get_node(".")
 | 
			
		||||
@onready var last_velocity:Vector2 = Vector2(0,0)
 | 
			
		||||
@onready var current_player:CharacterBody2D = null
 | 
			
		||||
 | 
			
		||||
@export var initial_impulse:Vector2 = Vector2(0,0)
 | 
			
		||||
 | 
			
		||||
# Called when the node enters the scene tree for the first time.
 | 
			
		||||
func _ready():
 | 
			
		||||
	print("Statue Ready!")
 | 
			
		||||
	if initial_impulse != Vector2.ZERO:
 | 
			
		||||
		rigid_body.apply_central_impulse(initial_impulse)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
func _on_body_entered(body):
 | 
			
		||||
	print("body entered! ")
 | 
			
		||||
	if body.is_in_group("player"):
 | 
			
		||||
		print("Player collided!")
 | 
			
		||||
		current_player = body
 | 
			
		||||
		current_player.player_hit.is_player_hit = true
 | 
			
		||||
		current_player.player_hit.hit_velocity = last_velocity
 | 
			
		||||
		
 | 
			
		||||
		if last_velocity.x > 50 or last_velocity.y < -50 or last_velocity.x < -50 or last_velocity.y > 50:
 | 
			
		||||
			current_player.health_changed_func(-1)
 | 
			
		||||
			rigid_body.set_sleeping(true)
 | 
			
		||||
							
								
								
									
										32
									
								
								PhysicsObjects/HandStatue/HandStatue.tscn
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								PhysicsObjects/HandStatue/HandStatue.tscn
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,32 @@
 | 
			
		||||
[gd_scene load_steps=5 format=3 uid="uid://ca4ghctk5gllj"]
 | 
			
		||||
 | 
			
		||||
[ext_resource type="Texture2D" uid="uid://cgtkkroa583fo" path="res://TileSets/Stuff.png" id="1_462gd"]
 | 
			
		||||
[ext_resource type="Script" path="res://PhysicsObjects/HandStatue/HandStatue.gd" id="1_ap0lt"]
 | 
			
		||||
 | 
			
		||||
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_ho34d"]
 | 
			
		||||
friction = 0.54
 | 
			
		||||
rough = true
 | 
			
		||||
bounce = 0.76
 | 
			
		||||
 | 
			
		||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_uay4g"]
 | 
			
		||||
radius = 9.0
 | 
			
		||||
height = 34.0
 | 
			
		||||
 | 
			
		||||
[node name="HandStatue" type="RigidBody2D" groups=["moveable"]]
 | 
			
		||||
physics_material_override = SubResource("PhysicsMaterial_ho34d")
 | 
			
		||||
contact_monitor = true
 | 
			
		||||
lock_rotation = true
 | 
			
		||||
script = ExtResource("1_ap0lt")
 | 
			
		||||
initial_impulse = Vector2(200, 0)
 | 
			
		||||
 | 
			
		||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
 | 
			
		||||
position = Vector2(0, -4)
 | 
			
		||||
shape = SubResource("CapsuleShape2D_uay4g")
 | 
			
		||||
 | 
			
		||||
[node name="Texture2D" type="Sprite2D" parent="."]
 | 
			
		||||
position = Vector2(0, -4)
 | 
			
		||||
texture = ExtResource("1_462gd")
 | 
			
		||||
region_enabled = true
 | 
			
		||||
region_rect = Rect2(48, 36, 16, 28)
 | 
			
		||||
 | 
			
		||||
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
 | 
			
		||||
		Reference in New Issue
	
	Block a user