Quantcast
Channel: Questions in topic: "javascipt"
Viewing all articles
Browse latest Browse all 1875

Object not following mouse

$
0
0
So I have a script going that sorta half works as intended. The way I need it to work is the object will follow the mouse around as long as the left mouse button is held, however as I have it, the object will only move to a different position within it's own Collision box. Here's the script : #pragma strict public var atom : GameObject; function Update () { var v3T = Vector3(Input.mousePosition.x, Input.mousePosition.y, 10); v3T = Camera.main.ScreenToWorldPoint (v3T); if(Input.GetMouseButtonDown(0)){ var hit : RaycastHit; var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition); if(Physics.Raycast(ray, hit)){ if(hit.collider.tag == "Atom"){ Debug.Log(hit.collider.gameObject.name); atom = hit.collider.gameObject; atom.transform.position = v3T; } } } if(Input.GetButtonUp("Fire1")){ atom = null; Debug.Log("Object Dropped"); } } Just to be clear, the way I want it to work is the object will follow the mouse around while the left mouse button is pressed, and will simply stop following once the mouse button is no longer pressed and will stay in that position. Any help is greatly appreciated.

Viewing all articles
Browse latest Browse all 1875

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>