Guns travel towards player

This commit is contained in:
2024-10-27 18:15:14 -07:00
parent 89953e7cd6
commit 73ab694f7c
3 changed files with 8 additions and 4 deletions

View File

@@ -30,7 +30,7 @@ Transform:
serializedVersion: 2
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 2.2222223, y: 2.2222223, z: 2.2222223}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}

View File

@@ -52,7 +52,7 @@ MonoBehaviour:
damageTimeoutSeconds: 0.5
health: 10
gun: {fileID: 5213001249979318174, guid: 98b57b15498e96a9c8fe56264ac2ef63, type: 3}
throwSpeed: 0
throwSpeed: 41.61
--- !u!212 &480941680556316754
SpriteRenderer:
m_ObjectHideFlags: 0

View File

@@ -15,9 +15,13 @@ public class GunThrower : Ratbot
}
void ThrowGun() {
GameObject thrown = Instantiate(gun);
GameObject thrown = Instantiate(
gun,
transform.position,
Quaternion.identity
);
thrown.GetComponent<Rigidbody2D>().AddRelativeForce((
transform.position - player.transform.position
player.transform.position - thrown.transform.position
).normalized * throwSpeed);
thrown.GetComponent<Gun>().damageStrength = damageStrength;
}