x


Set bounds of collider added at runtime

I am trying to add the bounds of a collider that is added at runtime. For some reason, I am unable to see updates to center or size or extent when I set it using the below:

var p = new GameObject("box");
p.AddComponent(BoxCollider);
p.collider.bounds.center = Vector3(4.5,4.5,4.5);

.
.
.

The resulting collider shows up in the inspector, but the values are always default, i.e., center and size aren't showing up as defined.

How do you set the bounds, center, and such of a collider added at runtime?

more ▼

asked Mar 13 '12 at 03:46 AM

ina2 gravatar image

ina2
61 5 6 9

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

1 answer: sort voted first

I don't think you can assign the bounds of a collider directly. However, the collider itself has center and extents properties that you can assign. As an example:

    GameObject go = new GameObject();
    BoxCollider collider = go.AddComponent<BoxCollider>();
    collider.center = new Vector3(2, 2, 2);
    collider.extents = new Vector3(9, 12, 18);
more ▼

answered Mar 13 '12 at 04:25 AM

simubrett gravatar image

simubrett
81 2 2 5

it looks like not calling it collider.bounds.center etc does the trick. thanks!

Mar 13 '12 at 06:03 AM ina2

in unity js... you actually have to call go.GetComponent(BoxCollider).center ... etc

Mar 13 '12 at 06:06 AM ina2
(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:

x2482
x2073
x1682
x1667
x94

asked: Mar 13 '12 at 03:46 AM

Seen: 2034 times

Last Updated: Mar 13 '12 at 06:06 AM