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"):
var b = Bullet.instance()
owner.add_child(b)
b.transform = $BulletGenerator.global_transform
b.velocity = -b.transform.basis.z * b.muzzle_velocity
b.transform = $CollisionShape/Tank/BulletGenerator.global_transform
b.velocity = -b.global_transform.basis.z * b.muzzle_velocity
var space_state = get_world().direct_space_state
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
if not intersection.empty(): # Make sure there is a intersection with raycast
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:
direction = direction.normalized()

View file

@ -9,20 +9,19 @@
[sub_resource type="SpatialMaterial" id=3]
albedo_color = Color( 1, 0, 0, 1 )
[node name="PlayerTank" type="Spatial"]
[node name="KinematicBody" type="KinematicBody" parent="."]
[node name="PlayerTank" type="KinematicBody"]
script = ExtResource( 1 )
[node name="CollisionShape" type="CollisionShape" parent="KinematicBody"]
shape = SubResource( 1 )
[node name="Camera" type="Camera" parent="KinematicBody"]
[node name="Camera" type="Camera" parent="."]
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 )
skeleton = NodePath("../..")
material/0 = SubResource( 3 )
[node name="BulletGenerator" type="Position3D" parent="KinematicBody"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1.6976, 0.375606, 0.0906463 )
[node name="BulletGenerator" type="Position3D" parent="CollisionShape/Tank"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0032903, 0.375606, -1.3599 )