Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 conflictbliz · Aug 02, 2011 at 05:37 PM · movementmousefollow

move script problem

here is my script i want my car to move towards the mouse so i have a mouse look script for that. I want it to move towards the mouse so i made a new script called mouse move, here's what i have:

function Update () 
{        
  if (Input.GetMouseButtonDown(0))
    new Vector3(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"), 0);
}

Comment
Add comment · Show 3
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 Meltdown · Aug 02, 2011 at 05:41 PM 0
Share

Please edit your post and format your code with the 1010 button, to make it more readable. Secondly, what is wrong with your script? What part of it doesn't work? What have you tried/haven't tried?

avatar image Chris D · Aug 02, 2011 at 05:56 PM 1
Share

Take a look at other "mouse look" questions on the site. Once you've oriented your game object correctly, you can use @GBStudios' suggestion below.

avatar image aldonaletto · Aug 02, 2011 at 05:58 PM 1
Share

I edited the script for you - follow @$$anonymous$$eltdown suggestion whenever you post some question here (select the code and click the 101010 button to format it). That's all you have in your script? It does nothing! (I suspect it doesn't even compile). It just creates a Vector3 with x and y set to $$anonymous$$ouse X and $$anonymous$$ouse Y values. This vector should be assigned to some variable, and this variable should be used to control the movement. What's your car? A rigidbody or a CharacterController? Or just a model?

1 Reply

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

Answer by AVividLight · Aug 02, 2011 at 05:50 PM

Hey Conflictbliz,

I am not quite sure what your problem is, but if you just want it to move forward when you push 0, I can help...

It will be something like this:

In C#:

  if(Input.GetKey("0"))
  transform.Translate(Vector3.forward * Time.deltaTime * 1);

In JavaScript:

 if(Input.GetKey("0")) {
 transform.Translate(Vector3.forward * Time.deltaTime * 1);
 }

I hope you can get it working!

-Gibson

Comment
Add comment · Show 3 · 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
avatar image conflictbliz · Aug 03, 2011 at 03:19 AM 0
Share

thanks i copied the fpswalker script and added that ins$$anonymous$$d of the delta time it had and now i have it always moving towards my mouse without a character controller but it wont stop and shouldn't it be if (Input.Get$$anonymous$$ouseButton(0)

avatar image conflictbliz · Aug 03, 2011 at 03:22 AM 0
Share

sorry guys the 10101 button is not working correctly could it be chrome and thanks to Gibson i edited his script a little bit and i got it to work so when i click the car moves when i unclick the car stops thanks alot really help because now i can move the car without a character controller giving it physics.

avatar image AVividLight · Aug 03, 2011 at 03:23 AM 0
Share

It can be... those were just suggestions!

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.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Attach an object to the mouse cursor? 0 Answers

Moving while facing the camera 0 Answers

moving an object with mouse ( my script is not smooth enough ) 0 Answers

Mouse Aiming Follow Wrong Direction - Help 2 Answers

Detecting which way my mouse is moving the most 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges