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 ZXYNINE · Dec 23, 2014 at 03:02 AM · mousedragcamera-look

Camera orbit and object following

I have two questions so ill just put both here- The first question i have is i have a script that i put on my camera that will allow me to look around it when you move the mouse but my issue is that it wont move up and down only around the object here is the script -

 using UnityEngine;
 using System.Collections;
 
 public class Orbit : MonoBehaviour {
     
     public float turnSpeed = 4.0f;
     public Transform player;
     
     public float height = 1f;
     public float distance = 2f;
     
     private Vector3 offsetX;
     private Vector3 offsetY;
     
     void Start () {
         
         offsetX = new Vector3 (0, height, distance);
         offsetY = new Vector3 (0, 0, distance);
     }
     
     void LateUpdate(){
         offsetX = Quaternion.AngleAxis (Input.GetAxis("Mouse X") * turnSpeed, Vector3.up) * offsetX;
         offsetY = Quaternion.AngleAxis (Input.GetAxis("Mouse X") * turnSpeed, Vector3.right) * offsetY;
         transform.position = player.position + offsetX; 
         transform.LookAt(player.position);
 
     }
 }

Question two is i have it so when you click on an object you can move it around so its like telekinesis but if i move my mouse under the terrain it will just go right through the terrain and if i move my mouse real quick and let go it will just drop from when i droped it from instead of flinging out i want a way so instead of just plain moving it it will make the object follow so that it will try to go unter the terrain but it wont any help?

Comment
Add comment · Show 6
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 CodeElemental · Dec 23, 2014 at 02:41 PM 0
Share

Please check the $$anonymous$$ouse axis that you are checking in the LateUpdate() method. Input.GetAxis("$$anonymous$$ouse X") is checked in both cases (for vertical and horizontal movement. (Or the na$$anonymous$$g of the variables is misleading/wrong)

avatar image RedHedZed · Dec 23, 2014 at 02:49 PM 0
Share

As far as looking around using the mouse goes, I'm pretty sure Unity has a script just for this already. $$anonymous$$ight be called $$anonymous$$ouseLook.cs?

As for being able to move the object around, does the object have a rigidbody? I'm betting you're changing the transform.position value. This means that you are effectively teleporting the object to a new location when it moves. So you're forcing it through other colliders like the ground.

Perhaps try adding a rigidbody to your object and moving it using forces?

As for throwing the object, when you let go apply a force or set the rigidbody's velocity to some value. Since it doesn't have a force being applied to it, and it doesn't have a velocity, it just drops straight down when you let go of it.

avatar image ZXYNINE · Dec 23, 2014 at 03:03 PM 0
Share

You see red i made my own that is a 3rd person camrea that will allow you to look around your character without changing anything but the cameras position it is a nice script that i would like to keep using. As for the moving of the object i was using raycasting to move it around all i want is for the object to follow the mouse ins$$anonymous$$d of tping right to it and that should fix the moving of the object as well because if i gt enough speed whith it following the mouse then i should just be able to let go and have it fling

avatar image RedHedZed · Dec 23, 2014 at 03:55 PM 0
Share

So you're casting a ray from the mouse to the object and moving it along said ray?

You could try using a Vector3.$$anonymous$$oveTowards or a Vector3.Lerp to make the object move towards the mouse position, and then when you let go "turn off" your movetowards or lerp.

avatar image ZXYNINE · Dec 23, 2014 at 04:48 PM 0
Share

Alright... im decently new to unity tho do you think you can help? I have no clue on how to do that.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by flapy-monkey · Dec 23, 2014 at 05:04 PM

alt text

what u wanna do?


qq20141224-4@2x.jpg (71.3 kB)
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.

Follow this Question

Answers Answers and Comments

28 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 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 avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

How to properly convert mouse pos to world pos 1 Answer

OnMouseUp() Click Display Effect. 1 Answer

How to rotate an object around another facing to mouse? 1 Answer

newbie: drag a rigidbody with mouse 2 Answers


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