Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
transform.forward is zero?
I'm working on integrating Curvy into my 2D space shooter game. I have some ships currently set to a forward direction of 0,-1 so they move down in the Y direction. These work great by applying a force in the forward direction * speed such as

lasers[laserIndex].rigidbody2D.AddForce(transform.forward * 3500.0f);

However, when I have a ship following a CurvySpline, it's transform.forward.x and transform.forward.y always equal zero and adding force just ends up with the projectile not moving at all. How do I get the facing direction of an object following a CurvySpline so I can shoot my projectiles in the correct direction?
CurvySpline.GetTangent() gives you the direction of the spline at a certain point while CurvySpline.GetOrientationFast() gives you a quaternion just like transform.rotation (i.e. direction and orientation/up-vector combined) (see the Reference).
Thanks. I'll give this a try and see how it goes.

Hmmm. GetTangentFast seems to be the easiest way to do it by just passing TF. But how do I get the current TF value? It doesn't seem to be accessible from the FollowSpline script.  It would be nice if every function in your documentation had an example of code on how to use it. I've found that to be immensely helpful when trying to figure out how a set of classes is supposed to work. It also avoids questions like this. I'm sure I'm just missing something simple.

Correction. It IS accessible. My bad. I made a typo. I'll give it a shot and report back.

That worked. In my case I just need to reverse the direction though. It seems to be getting everything backwards, inclouding this direction. But I can work that out. Thanks for the help. This saves me a lot of headache trying to implement a workaround. My project was stalling because of this. I can get back to making progress again.

Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I make the computer ignore it's parent transform? eastes 3 7 04-06-2022, 12:16 PM
Last Post: _Aka_
  Connect knots to transform BanksySan 3 1,181 01-11-2021, 08:06 AM
Last Post: _Aka_
  Rigidbody or Transform Movement ATHellboy 10 6,577 02-04-2020, 08:37 PM
Last Post: _Aka_
  Generating multiple object on changing transform jawadkhan.9026 12 10,547 09-06-2019, 09:39 PM
Last Post: _Aka_

Forum Jump: