diff --git a/prefab/bullet/OrdinaryBullets.tscn b/prefab/bullet/OrdinaryBullets.tscn
index e62a12b..2b67735 100644
--- a/prefab/bullet/OrdinaryBullets.tscn
+++ b/prefab/bullet/OrdinaryBullets.tscn
@@ -1,27 +1,16 @@
-[gd_scene load_steps=5 format=2]
+[gd_scene load_steps=4 format=2]
[ext_resource path="res://src/bullet/OrdinaryBullets.cs" type="Script" id=1]
[ext_resource path="res://resource/sprite/bullet/bullet.png" type="Texture" id=2]
[ext_resource path="res://prefab/effect/Hit.tscn" type="PackedScene" id=3]
-[sub_resource type="RectangleShape2D" id=1]
-extents = Vector2( 0.5, 0.5 )
-
-[node name="OrdinaryBullets" type="KinematicBody2D"]
-collision_layer = 2
+[node name="OrdinaryBullets" type="RayCast2D"]
+enabled = true
+cast_to = Vector2( 8, 0 )
script = ExtResource( 1 )
-__meta__ = {
-"_edit_horizontal_guides_": [ ],
-"_edit_vertical_guides_": [ ]
-}
Hit = ExtResource( 3 )
[node name="Bullet" type="Sprite" parent="."]
-position = Vector2( 1, 0 )
-scale = Vector2( 0.063, 1 )
+position = Vector2( 7, 0 )
texture = ExtResource( 2 )
offset = Vector2( -7.5, 0 )
-
-[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
-position = Vector2( 0.5, 0 )
-shape = SubResource( 1 )
diff --git a/resource/sprite/bullet/bullet.png b/resource/sprite/bullet/bullet.png
index fbf24ef..e9c30ef 100644
--- a/resource/sprite/bullet/bullet.png
+++ b/resource/sprite/bullet/bullet.png
Binary files differ
diff --git a/src/bullet/OrdinaryBullets.cs b/src/bullet/OrdinaryBullets.cs
index 7da7f58..34b0d71 100644
--- a/src/bullet/OrdinaryBullets.cs
+++ b/src/bullet/OrdinaryBullets.cs
@@ -3,7 +3,7 @@
///
/// 普通的子弹
///
-public class OrdinaryBullets : KinematicBody2D, IBullet
+public class OrdinaryBullets : RayCast2D, IBullet
{
public CampEnum TargetCamp { get; private set; }
@@ -24,8 +24,6 @@
private float FlySpeed = 1500;
//当前子弹已经飞行的距离
private float CurrFlyDistance = 0;
- //碰撞数据
- private KinematicCollision2D CollisionData = null;
//子弹的精灵
private Sprite BulletSprite;
@@ -42,39 +40,37 @@
BulletSprite = GetNode("Bullet");
// BulletSprite.Visible = false;
- Scale = new Vector2(FlySpeed / 60 * 1.5f, 1);
-
- GD.Print("---------------1" + GlobalPosition);
+ Scale = new Vector2(1.8f, 1);
}
public override void _PhysicsProcess(float delta)
{
- GD.Print("---------------2" + GlobalPosition);
- if (CollisionData != null) //碰到物体
+ if (IsColliding())
{
- // 销毁
- QueueFree();
+ var pos = GetCollisionPoint();
+ GlobalPosition = pos;
Node2D hit = Hit.Instance();
hit.RotationDegrees = MathUtils.RandRangeInt(0, 360);
- hit.GlobalPosition = CollisionData.Position;
+ hit.GlobalPosition = pos;
GetTree().CurrentScene.AddChild(hit);
- return;
- }
-
- // 移动
- CollisionData = MoveAndCollide(Vector2.Right.Rotated(GlobalRotation) * FlySpeed * delta);
-
- if (CurrFlyDistance == 0)
- {
- BulletSprite.Visible = true;
- }
-
- CurrFlyDistance += FlySpeed * delta;
- if (CurrFlyDistance >= MaxDistance)
- {
QueueFree();
}
+ else
+ {
+ Position += new Vector2(FlySpeed * delta, 0).Rotated(Rotation);
+
+ if (CurrFlyDistance == 0)
+ {
+ BulletSprite.Visible = true;
+ }
+
+ CurrFlyDistance += FlySpeed * delta;
+ if (CurrFlyDistance >= MaxDistance)
+ {
+ QueueFree();
+ }
+ }
}
}
\ No newline at end of file