4
2011
Follow / Push object
Follow / push object around.
Might be useful for something..??
Webplayer:
http://unitycoder.com/upload/demos/mFollow1/
Original source:
http://processing.org/learning/topics/follow1.html
Download webplayer package: (unity js)
(coming soon..)
Source: (.js)
// mFollow ported to Unity : mgear : http://unitycoder.com/blog // attach this script to camera, then assign some object(with linerenderer) as "object" // original : http://processing.org/learning/topics/follow1.html // All Examples Written by Casey Reas and Ben Fry // unless otherwise stated. private var x:float = 0; private var y:float = 0; private var angle1:float = 0.0; public var segLength:int = 2; public var object : Transform; private var mousePos:Vector3; // mainloop function Update () { // get mouse position mousePos = Input.mousePosition; mousePos.z = 10.0; // fixed distance from camera // convert mousepos into world pos var MouseWorldPos = Camera.main.ScreenToWorldPoint(mousePos); // not sure whats happening here.. var dx:float = MouseWorldPos.x-x; var dy:float = MouseWorldPos.y-y; var angle1:float = Mathf.Atan2(dy, dx); x = MouseWorldPosOrig.x - (Mathf.Cos(angle1) * segLength); y = MouseWorldPosOrig.y - (Mathf.Sin(angle1) * segLength); // set object pos object.transform.position = Vector3(x,y,10); // draw line from object to mouse var lineRenderer : LineRenderer = object.GetComponent(LineRenderer); lineRenderer.SetPosition(0,MouseWorldPos); lineRenderer.SetPosition(1,object.transform.position); }
Related Posts
1 Comment + Add Comment
Leave a comment
Recent posts
- [GreaseMonkey] Unity Forum Fixer
- UnityHub: Make Hub application background Translucent
- Customize SpriteShapeRenderer quality (but has issues)
- Editor tool: Copy selected gameobject’s names into clipboard as rows (for Excel)
- Editor tool: Replace string in selected gameobject’s names
- UnityHub: Enable built-in Login Dialog (no more browser login/logout issues!)
- Use TikTok-TTS in Unity (with WebRequest)
- Create Scene Thumbnail Image using OnSceneSaved & OnPreviewGUI
- webgl+javascript TTS
- Using Moonsharp (LUA) + Unity Webgl
- Using 3D gameobject prefabs with Unity Tilemap + NavMesh Surface
- Custom Unity Hub Project Template Preview Image/Video (using HTML+CSS in package description)
Recent Comments
- Vector3 maths for dummies! on
- UnityHub: Make Hub application background Translucent on
- UnityHub: Make Hub application background Translucent on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- [Asset Store] Point Cloud Viewer & Tools on
- [Asset Store] Point Cloud Viewer & Tools on
- ffmpeg stream raw video into Unity Texture2D on
x, y represents the position of object, then draw a line from mouseWorldPos to object