Can't position bullet start position with scripting right. Please help

Ok, so I wanted to make shotgun for my game using a tutorial made by Pineapple Brain. I made everything like how it was in the video except for one function that changed a bit since tutorial video was uploaded. And I stumbled upon two problems:

  1. When my unit shoots (it’s a top-down game btw), bullets are somewhat off-set, like their start position is off.
  2. For some reason, I can’t set the owner of last created projectile.

Script for creating a bullet and setting ownership:

Script for bullet’s damage and reward for killing:

In addition, in damage script, I’ve made so that when unit starts touching projectile, it sends a chat message, simply saying a nickname of owner of source unit’s owner, but all that it says is:
undefined bruh

I may understand the part with wrong start position of my bullets, but I’m really confused as of why ownership of projectile isn’t setting up. I hope someone can give me an answer, I’d be gladly thankful :slight_smile:

4 Likes

Ok, so I figured out the problem with owner of projectile (I didn’t set up last attacking unit once touching :sweat_smile:)
I still have the problem with bullets though, but I noticed that bullets spawn infront of item as entity (kinda in right direction if that makes sense)
Here, look:

Right (most normal looking)
right

Down:
down

Left (cant see it because projectile spawns right inside the bullet)
left

And up:
up

4 Likes

You should get a position in front of the position of the triggering item at the facing angle of the triggering unit. The ‘get position in front of position’ function also returns a position that is 90 degrees off from the entity’s facing angle, so subtract 1.5708 from the angle you want between the original position and new position and set that as the angle in ‘get position in front of position’. Your projectile creating action would be ‘create Shotgun Bullet at (get position in front of (position of (triggering item)) at a distance 22 at an angle ((facing angle of (triggering unit) - 1.5708))…’

5 Likes

I know this isn’t easy to get cirtified.

3 Likes

That works, thank you much! Didn’t know angle of creation actually affects place where projectile gets created. If I got it right, this angle is relative to the mid point of item (not unit)… right?

4 Likes

In the picture, you’re setting the angle to “0”.

It means the bullet is placed at the absolute angle 0 (rightwards) no matter what direction your item is facing.

That’s why kyle is suggesting to change the angle according to the unit’s facing angle.
(Though I didn’t know I had to set a subtracted value to the angle :sweat_smile: )

4 Likes

As for the ownership, you destroyed the projectile before sending a chat message, and that’s why the chat says “undefined” (because it is no longer there).

4 Likes