- Home /
Floating weapon + shots aren't moving properly.
What I'm trying to do:
I'm trying to have a floating sphere that follows the player (shown below) shoot blasts at what the camera is facing.
What is happening instead:
When I press and hold the left mouse button, the blasts appear at my character's feet, not the sphere.
The trail of blasts in the image below show how the blasts move - or, more importantly, how they don't.
Update:
Solved the blast spawn problem. The script was attached to the sphere's main parent object (i.e. "weapon name"), not the sphere itself.
Answer by 017Bluefield · May 27, 2015 at 06:31 AM
For reference, here's the hierarchy of the weapon:
Weapon > Sphere > BlastSpawn
Attach the blast spawn script to the Sphere itself.
Add the following script to the BlastSpawn:
using UnityEngine; using System.Collections; public class GrimoireBlast : MonoBehaviour { public Rigidbody projectile; public Transform shotPos; public float shotForce = 1000f; void Start(){ // For use later } void Update () { if(Input.GetButtonUp("Fire1")) { Rigidbody shot = Instantiate(projectile, shotPos.position, shotPos.rotation) as Rigidbody; shot.AddForce(shotPos.forward * shotForce); } } }
Your answer
![](https://koobas.hobune.stream/wayback/20220613193922im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Irregular position when instantiating clone during camera rotation? 1 Answer
My shooting system wont work, help 1 Answer
Need help putting an object at a point based on screen coordinates 1 Answer
Instantiating camera crashes my pc 0 Answers
Instantiate gun & arms rig relative to rotation & position of first person controller camera 0 Answers