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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Lewenos 1 · Apr 25, 2011 at 01:15 PM · throughmmorpgclicktomovepoint-and-click

click to move script goes through objects

Hi. I have problem with this:

using UnityEngine; using System.Collections;

public class Click2Move : MonoBehaviour { public Camera PlayerCam; public Transform mover; //the object being moved public float SnapTo = 0.5f; //how close we get before snapping to the desination private Vector3 destination = Vector3.zero; //where we want to move

 // Use this for initialization
 void Start ()
 {
     destination = mover.position; //set the destination to the objects position when the script is run the first time
 }

 // Update is called once per frame
 void Update()
 {
     //when left mouse button is pressed
     if (Input.GetMouseButtonDown(0))
     {
         Ray ray = (PlayerCam.ScreenPointToRay(Input.mousePosition)); //create the ray
         RaycastHit hit; //create the var that will hold the information of where the ray hit

         if (Physics.Raycast(ray, out hit)) //did we hit something?
             if (hit.transform.name == "Ground") //did we hit the ground?
                 destination = hit.point; //set the destinatin to the vector3 where the ground was contacted
     }

     // move the object toward the destination
     if (Vector3.Distance(mover.position, destination) < SnapTo) //are we within snap range?
         mover.position = destination; //snap to destination
     else 
         mover.position = Vector3.MoveTowards(mover.transform.position, destination, Time.deltaTime * 4); //move toward destination
 }

}

Click2Move script.. Script works like this: Attach it to camera, put your player to "mover" and change snap to 0. Then drag your camera to "PlayerCam"..

And when you have object in front of you and you click to other side of it, player goes through object, even if object haves collider!

Please help me!

Lewenos

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 Scribe · Apr 25, 2011 at 01:55 PM 0
Share

have you added a rigid body to you player If you dont want gravity just turn it off but I found it enables collisions.

hope this is helpful

avatar image Justin Warner · Apr 25, 2011 at 02:11 PM 0
Share

Next time, highlight the code and push the lil 10101 button up top =). Thanks a lot! =D

avatar image Lewenos 1 · Apr 25, 2011 at 05:28 PM 0
Share

Justin Warner: Oh, sure :)

Scribe: No, i will add, thanks.

0 Replies

· Add your reply
  • Sort: 

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

Click to move script, need help. 1 Answer

When near object, able player to click it and then player teleports. 1 Answer

Can I make a MMORPG with unity? 20 Answers

Quick Terrain Sizing Question! 0 Answers

Help with variables... 0 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