x


Dynamically Update Instantiated Objects Position

Is it possible instantiate an object once in the manner of "OnMouseUp" and then define its transform position of a bone that in on a model in a scene? I desire a laser beam to attach to a models bone and move with it.

Thanks M8s

more ▼

asked Nov 09 '10 at 08:54 AM

KSLR gravatar image

KSLR
1 1 1 1

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

"define its transform position of a bone that in on a model"? I have no idea what that is supposed to mean. Please consider rephrasing.

Your description is quite poor. Do you mean the OnMouseUp function which only happens when the mouse is released over an object with a Collider or OnMouseUp in general which would be if(Input.GetMouseUp(0)) or the like?

Going from what you describe in the latter part of your question, you want an object "laser" to move with some other object "bone", right? That can be achieved through parenting:

var bone : Transform; //instance in the scene. Get it however you like.
var laser : Transform; //prefab
var offset : vector3; //Where to place laser relative to bone

function OnMouseUp() (
    if(!laser || !bone) return;
    var instance : transform = Instantiate(laser, bone.TransformPoint(offset),
                                           bone.rotation);
    instance.parent = bone;
)

If your laser is a particle system or something that you turn on/off often enough, it is simpler to just add this part to the prefab and turn it off/stop emitting. Please see the 3D platformer tutorial's jetpack example of how to do this.

more ▼

answered Nov 09 '10 at 04:50 PM

skovacs1 gravatar image

skovacs1
10k 11 25 91

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1670
x1276
x884
x231
x143

asked: Nov 09 '10 at 08:54 AM

Seen: 1044 times

Last Updated: Nov 09 '10 at 08:54 AM