- Home /
[C#]Instantiate projectile a distance away from Player
Hello,
I'm currently designing a 2D shooting game where the player fires a projectile off from itself. I've managed to pull off the spawning of the projectile from the player with Instantiate my prefab projectile, and it does fire off smoothly in game. Only problem is that it directly spawns at the player's center position.
I've tried to find answers on how to spawn it from the Player's cannon barrel itself, but am unable to do so. Here is the code in question for the Player:
void fire(){
GameObject clone = (GameObject)Instantiate (projectile, transform.position, transform.rotation);
}
I've persumably tried to tweak the transform.position in this particular code by using Vector2(0, 0.1) to allow my projectile to spawn infront of the player. But instead I got coding errors. I currently have 2 scripts, the bulletcontroller and the player. I suspect that either I can fix it directly on the void fire() script or move the projectile from the bulletcontroller script.
Any help would be appreciated, thanks.
Your answer
Follow this Question
Related Questions
Very basic Instantiate Question 2 Answers
Char shots oneside only / kills enemy on specific place. 0 Answers
Shooting style like enter the dungeon 0 Answers
Enemy Damage problem 1 Answer
Can't stop shooting myself 2 Answers