• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by kyaranger · May 08, 2013 at 07:52 PM · vector math

Moving a gameobject on a certain direction

Hi,

So, I have two gameobjects, a player and a crosshair. The crosshair is always 20 units in the forward direction of the player, with its y value set to 0. What I would like is to launch another gameobject, a projectile, from the player, to the crosshair. This is what I attempted.

When the player presses space, I run this little script

Instantiate( missile, transform.position, transform.rotation);

And in the missile start function I do this.

Vector3 direction = crosshair.transform.position - player.transform.position; direction.Normalize();

and in the Update function for missile, I do this

transform.Translate((direction moveSpeed Time.deltaTime));

But I get wierd results, it works when the player is facing a certain direction, but as it rotates, the direction keeps getting more and more inaccurate.

Any ideas?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ExTheSea · May 10, 2013 at 07:52 AM 0
Share

If your problem is solved please accept an answer or close the question.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by ExTheSea · May 08, 2013 at 08:11 PM

I don't think

  Vector3 direction = crosshair.transform.position - player.transform.position;     direction.Normalize();`

will give you the right results.

Why don't you use the transform.forward of your player? This Vector points in the direction the transform is facing.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Material doesn't have a color property '_Color' 4 Answers

How to import the object from server to unity 2 Answers

Setting Scroll View Width GUILayout 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges