Improved colliders and projetiles

This commit is contained in:
Paul Black 2022-03-03 20:25:46 -07:00
parent 5e03c4549b
commit 75f19e9999
2 changed files with 12 additions and 13 deletions

View file

@ -22,8 +22,8 @@ func _physics_process(delta):
if Input.is_action_just_pressed("shoot"): if Input.is_action_just_pressed("shoot"):
var b = Bullet.instance() var b = Bullet.instance()
owner.add_child(b) owner.add_child(b)
b.transform = $BulletGenerator.global_transform b.transform = $CollisionShape/Tank/BulletGenerator.global_transform
b.velocity = -b.transform.basis.z * b.muzzle_velocity b.velocity = -b.global_transform.basis.z * b.muzzle_velocity
var space_state = get_world().direct_space_state var space_state = get_world().direct_space_state
var mouse_position = get_viewport().get_mouse_position() var mouse_position = get_viewport().get_mouse_position()
@ -32,7 +32,7 @@ func _physics_process(delta):
var intersection = space_state.intersect_ray(rayOrigin, rayEnd) # Set variable for cursor position var intersection = space_state.intersect_ray(rayOrigin, rayEnd) # Set variable for cursor position
if not intersection.empty(): # Make sure there is a intersection with raycast if not intersection.empty(): # Make sure there is a intersection with raycast
var pos = intersection.position var pos = intersection.position
$Tank.look_at(Vector3(pos.x, pos.y, pos.z), Vector3(0,1,0)) $CollisionShape.look_at(Vector3(pos.x, pos.y, pos.z), Vector3(0,1,0))
if direction != Vector3.ZERO: if direction != Vector3.ZERO:
direction = direction.normalized() direction = direction.normalized()

View file

@ -9,20 +9,19 @@
[sub_resource type="SpatialMaterial" id=3] [sub_resource type="SpatialMaterial" id=3]
albedo_color = Color( 1, 0, 0, 1 ) albedo_color = Color( 1, 0, 0, 1 )
[node name="PlayerTank" type="Spatial"] [node name="PlayerTank" type="KinematicBody"]
[node name="KinematicBody" type="KinematicBody" parent="."]
script = ExtResource( 1 ) script = ExtResource( 1 )
[node name="CollisionShape" type="CollisionShape" parent="KinematicBody"] [node name="Camera" type="Camera" parent="."]
shape = SubResource( 1 )
[node name="Camera" type="Camera" parent="KinematicBody"]
transform = Transform( 1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 20.7405, -7.28392e-07 ) transform = Transform( 1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 20.7405, -7.28392e-07 )
[node name="Tank" type="MeshInstance" parent="KinematicBody"] [node name="CollisionShape" type="CollisionShape" parent="."]
shape = SubResource( 1 )
[node name="Tank" type="MeshInstance" parent="CollisionShape"]
mesh = SubResource( 2 ) mesh = SubResource( 2 )
skeleton = NodePath("../..")
material/0 = SubResource( 3 ) material/0 = SubResource( 3 )
[node name="BulletGenerator" type="Position3D" parent="KinematicBody"] [node name="BulletGenerator" type="Position3D" parent="CollisionShape/Tank"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1.6976, 0.375606, 0.0906463 ) transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0032903, 0.375606, -1.3599 )