Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Having trouble moving projectiles from spline
Hi, I am having trouble getting projectiles to fire correctly from a ship that follows one spline and is offset from it on the z axis. I need to have the projectiles fire from the ship and stay aligned to the spline as it moves forwards. So I have placed an alignToSpline component on a point that is attached at the spline and have an empty object child at 0,0,0 with a ship parented to that point, offset from it. I have controls set up to move the ship forwards and backwards using alignToSpline.position. I have the empty gameobject use rotatearound to move the ship around the tunnel. Everything moves just fine. I have a projectile setup kind of the same, with a center point, empty game object and a projectile parented to the object. I have to instantiate the projectile by using instantiate(projectile) without position or rotation since it just snaps to the center and doesnt work. Im having trouble firing the projectile from the ships position, so far i can fire it from its poition but not its rotation. Ive tried a few diffrent things and still having trouble.

Ive been working on this for way longer then I should and only have headaches and wasted time. I can't imagine it should be this hard to do, it seems ive tried everything and am still stuck with little progress on the game. Im hoping you can point me in the right direction, Ive been putting off asking for help since i think I would have a hard time explaining it and having to write alot to do so, but im at the end and ready to give up. Since ive found curvy, Ive saved alot of time and headaches by creating a spline I was trying to make without it and wasnt doing so good. Im hoping to get all this working and finally get the bulk of it done. Please let me know what you think I should do, thanks!
Don't worry, we'll get this sorted. Do you want your projectiles follow the spline? Or move straight once shooted?

Also, feel free to post some parts of your code or a screenshot, so we can get a better idea of the problem...
Thanks for responding, I want the projectiles(lasers) to follow the same spline the ship is attached to, but at the ships location and rotation. So follow the spline but offset from it like the ship is. the projectiles would appear to follow the curve of the tunnel, the same path the ship is on when it is first fired.

Ive included pics and scripts to, hopefeully, give you a full understanding of my problem. I had to start a new scene with only the basics of what im trying to do so I can better debug things. I have alot of other scripts and prefabs, etc, most will need rewritten most likely, but anyways, the first pic( ) will show the ship parented to a transform, parented to the transform with the aligntospline component attached. the ship rotates around the centerpoint using horzontal axis, while vertical moves forward, modifying the curvyspline.position on the spcenter gameobject.

The second picture( ) shows the projectile(laser) parented to the centerpoint that is parented to the point containing the aligntospline component. its a prefab and the parent will instantiate to the point specified in the ship script, gameobject "spcenter".

the third picture( ) is another question I had Ive been wondering for a while. the texture seems to wrap around the tunnel, splitting in the middle, so the bottom and top of the texture dont line up and look bad. Im not sure if there is a way to fix this, im not sure if I used a custom model I made in blender and wrapped it in there or how it was made. Maybe theres a setting I can adjust.

The 2 scripts( ) I included are the only ones im using atm. I didnt edit it before sending it so there is alot commented out, but maybe that will help, and since im still new at c# and programming in general, it may seem a bit odd, but works for the most part. I left off adding spline.GetOrientationFast but I couldnt figure how to set it up or if its even what I want to use. I pretty much just do trial and error and learn as I go, lol. Im sure there is something that is wrong and could be written better. I hope you can find the issue or just see that im going about it completely wrong. Let me know if you need anything else and again, thanks alot.


ok so I changed the line in the curvylaser1 script from transform.parent.localEulerAngles = laserRotObject.localEulerAngles to laserStartPos; = transform.parent.localEulerAngles;

If I set the lasers speed to zero, (setorientation is true and dynamic is true) then it spawns right where it needs to be, in front of the ship at the ships rotation. Then when I change the speed to more then zero, the lasers rotation(the aligntospline component) wants to snap back to its default rotation. If I change the setOrientation to false, then it will shoot normally, infront of the ship at its rotation, but the laser will not keep its orientation along the spline, it will rotate a bit as it travels. If I uncheck dynamic, it will just spawn at its default position and rotation, position being zero and not that of the ship. It seems to want to "refresh" whenever dynamic is unchecked and setOrientation is checked. Im not sure if I should try and override the refresh command or what. I hope you can look at this and give me some anwsers cause im really struggling with this.

Possibly Related Threads…
Thread Author Replies Views Last Post
  Curvy Line Renderer for UI Spline? gekido 3 6 04-04-2024, 12:56 PM
Last Post: _Aka_
  Get position of all control points for a spline gekido 1 6 03-28-2024, 10:08 PM
Last Post: _Aka_
Bug Changing spline connection in inspector causes splines to revert to defaults lacota 3 6 03-18-2024, 07:55 PM
Last Post: _Aka_
  GO can't fit end of the spline GameDeveloperek4123 3 14 03-04-2024, 11:06 AM
Last Post: _Aka_

Forum Jump: