EDIT: My scripts work fine! My question is about proper usage of the Transform object and it's subordinate vectors. Please read carefully.
I've been writing scripts that make adjustments to some of the transform vectors. Take for instance a script that controls a missile tracking a target. I make some vectors and determine how much of an adjustment to make based on the allowed turning rate of the missile. Then I simply add the offset to transform.forward.
Does this make sense? Should I be using the Rotate method or Quaternions instead of this kind of direct modification?
Things seem to be working properly but does Transform automatically normalize and fix the other direction vectors when you modify one?
Why would anyone downvote this?
If people are going to downvote something - at least give a reason so the asker knows what they've done...
I'm not sure I understand what you're asking. Are you making modifications to the standard Vector3.up, Vector3.forward, etc.? As in Vector3.up = Vector3(0.53, 0.89, 0.1); and stuff like that? I didn't think that was possible, but that could just be my assumption because I'd never want to actually change them.
It sound like you want to have a smart missile that tracks the position of your target. A lot of player type aircraft uses evasive maneuvers thus avoiding missiles. Simply set your positional coordinate values of the missile incrementally towards that of your target.
@Byterunner.. No, I'm not changing the standard 'forward'. I'm changing gameObject.transform.forward. And it works, but I've never seen a reference to it so I'm wondering if that is crazy or not.
Answer by UniteMage
May 24, 2011 at 10:22 PM
Basic Chasing and Evading
if (missleX > targetX) missleX--;
if (missleX < targetX) missleX++;
Do the same for the other axes. Of course this is an over simplification.
http://www.gotow.net/andrew/blog/?page_id=78 take a look at the AI for steering left/right. It's a very good system. Simply calculate the relative position and apply steering based on it.
My tracking scripts work fine. My question was about the validity of directly modifying gameObject.transform.forward.. on the missile itself.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a user guide.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
Answers and Comments
2 People are following this question.
Collision Detection + Transform Offset Question
Move an object forward and not up?
Turn and Move Foward 1 Unit relative to Objects local direction
transform.foward returns transform.zero?
C# always move an object forward and still use physics