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:
When my unit shoots (it’s a top-down game btw), bullets are somewhat off-set, like their start position is off.
For some reason, I can’t set the owner of last created projectile.
Script for creating a bullet and setting ownership:
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:
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
Ok, so I figured out the problem with owner of projectile (I didn’t set up last attacking unit once touching )
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)
Down:
Left (cant see it because projectile spawns right inside the bullet)
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))…’
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?
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 )
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).