Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 MohdGasim · Apr 11, 2011 at 10:28 PM · cameraraycast3dspace

Move in direction of mouse look

Hi there....im working on a 3d 'space' type of scene and need the character (camera) to move in 3d space....i have assigned the mouse look and fps controller...my camera moves on a flat plane...i want it to move in the direction of the mouse look...i.e. when the mouse looks up and i press W the character moves up in space in the direction (not just Y axis, but diagonally)..i think it has something to do with raycast, but HOW.....is there anyone kind enough to assist me please....thanx

Comment
Add comment
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

2 Replies

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

Answer by Meater6 · Apr 11, 2011 at 11:41 PM

Hmm, I wouldn't use the fps controller. I suggest just making a script that translates the character in the local-Z direction. So when you look up, it translates that way. Or you can use a rigidbody and set it to not be affected by gravity, and create a script that modifies the velocity in a transformed direction. This is extremely simple, so if you know any scripting it should be easy to accomplish. If you need an example use of this, comment on this answer saying so.

EDIT: Here is a question about how to make transformed directions with rigidbody.velocity: Question Here is a script section on how to make a block fly in the direction it is facing:

var speed = 10.0;

//The vector we are going to move by private var moveDirection : Vector3;

var speed = 10.0;

//The vector we are going to move by private var moveDirection : Vector3;

function FixedUpdate () { //Set moveDirection to the vertical axis (up and down keys) * speed //For smoother movement use Input.GetAxis instead of Input.GetAxisRaw moveDirection = Vector3(0,0,speed*Input.GetAxisRaw("Vertical")); //Transform the vector3 to local space moveDirection = transform.TransformDirection(moveDirection); //set the velocity, so you can move transform.rigidbody.velocity = moveDirection; }

Edit it to your needs. It pretty much is all you need to make your camera fly back and forth. For a strafing effect, look at the fps walker script for the "Horizontal" axis part (The thing that determines the left right key inputs). I hope this was helpful, and is the answer to your question.

Comment
Add comment · Show 7 · 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 MohdGasim · Apr 13, 2011 at 06:28 AM 0
Share

will try this and get back to you with how it turned out...i appreciate your help...and i SUC$$anonymous$$ at scripting...loool

avatar image MohdGasim · Apr 13, 2011 at 06:58 PM 0
Share

hi...tried looking into how to make the rigid body transform using mouse look direction...NO idea...if u can assist me please, i would be greatful

avatar image MohdGasim · Apr 18, 2011 at 02:42 PM 0
Share

hi $$anonymous$$eater6...thanx for the code...was away from my computer for a couple of days...will try this later and get back to you and DaveA...thanx guys

avatar image MohdGasim · Apr 24, 2011 at 03:39 AM 0
Share

if i could give u more than a vote up i would....works like magic...thanx $$anonymous$$eater6

avatar image Meater6 · Apr 24, 2011 at 06:39 PM 0
Share

Umm, there is the "Correct Answer" button which looks like a check mark. This tells people that it is the right answer. Plus, it gives +15 rep. Glad it works.

Show more comments
avatar image
1

Answer by DaveA · Apr 11, 2011 at 11:33 PM

I think it has more to do with gravity. I modified FPSWalker, add these things:

public bool fly = false;

void FixedUpdate() { if (Input.GetKeyDown ("f3")) { fly = !fly; }

..... then the code that was there, then look for if (grounded)...

if (fly || grounded) {

... then look for Apply gravity moveDirection.y -= gravity * Time.deltaTime ....

// Apply gravity (if not flying) if (!fly) moveDirection.y -= gravity * Time.deltaTime;

Comment
Add comment · Show 6 · 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 Velketor · Apr 11, 2011 at 11:34 PM 0
Share

i agree with setting gravity to zero. this should simulate a free fps controller.

avatar image DaveA · Apr 12, 2011 at 02:45 AM 0
Share

Works for me. I put in a 'fly' mode by just ignoring gravity.

avatar image MohdGasim · Apr 13, 2011 at 06:27 AM 0
Share

hi..thanx for the feedback, but ignoring gravity makes you not fall, but doesnt allow you to fly...i tried it previously and thats where i got stuck...thanx again though

avatar image DaveA · Apr 13, 2011 at 07:09 AM 0
Share

I'll try to post some code when I get a chance

avatar image MohdGasim · Apr 13, 2011 at 11:48 AM 0
Share

thanx DaveA...will be waiting

Show more comments

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

No one has followed this question yet.

Related Questions

is it possible to have raycasts to cover the whole screen in one Update() time? 0 Answers

Moving player in direciton camera is facing 1 Answer

Raycast from one camera using a gameobject relative to another camera 1 Answer

Right way to set a canvas in stereo mode 0 Answers

Shoot nearest enemy with raycast 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