|
Hi Im having some problems with created (prefab) gameObjects and a raycast. I've created some cubes in the game with BoxColliders and using:
to show me this in the editor. This works fine. I then created a new gameObject:
where newObject is a prefab created beforehand from a resource. What do I have to do to get the raycast working on this object? a box collider would do. I tried:
The gameObject gets a rigidbody and a boxcollider, but my raycast does not show up? Do I need to reinitiate something for the raycast to work? does the original file have to be somewhere else as in the resource file, with which I created the prefab. I checked the layers aswell, both are in Default. thxs Ent Added complete script: its the: Debug.DrawLine (ray.origin, hit.point); not showing up whats bothering me. Im will add a colliderBox to the prefab to check if its something else. The DistanceToGround is confusing because I havent changed the Var name from the example I had, should be DistanceToCamera. objectscript (JS):
objectscript (CS):
camerascript:
(comments are locked)
|
|
gameObject.layer = numOfLayer; Regarding your main question we could use some info. You don't say how you create the ray, where your ground is and if/where you move the new object. If your ground is at (0,0,0) and you create a new object at the same position a raycast will probably not hit this object... I checked your script and it works for me. Only thing I changed was the camera script:
It draws the rays for manually placed items as well as for instantiated prefabs. Maybe you should check out if the colliders are configured correctly on the instantiated prefabs? I am creating multiple pieces next to each other, so at least one should not be at 0,0,0 :) they are not moved. They are near the cubes I created before, so it should be working.
Jun 17 '10 at 08:37 AM
Ent
Maybe you could post the whole code you have right now. (At least the part that is bothering you) Otherwise all we can do is make wild guesses... ;)
Jun 17 '10 at 09:00 AM
StephanK
Ive posted the complete script above
Jun 17 '10 at 10:14 AM
Ent
It works for me as it's supposed to...
Jun 17 '10 at 11:35 AM
StephanK
Strange, it works when I create a cube and place this in a prefab. But not when I am using a 3DMax Obj file in a prefab. To make a prefab, dont you just 'CREATE PREFAB' and pull the object into the prefab? K, my mistake :) cant pull resources into the game ^^. Could that be the problem? I just pulled my resource file from the resource folder onto my prefab. It seemed to work but that might be my problem.
Jul 13 '10 at 06:34 AM
Ent
(comments are locked)
|

It's not clear to me from your question, but is there a reason why you can't just setup the prefab to have all the components and settings that you require, so any instance you create will already have them?
I dont always know which collider fits best beforehand, because the meshs will get changed later. So its more like if its object1 use mesh1 and box, if its object2 use mesh2 and Sphere and if it is object3 use mesh3 and mesh collider. I cant make prefabs for all mesh colliders.
Fair enough.
Without testing your code - you're aware that Debug.DrawLine only appears in the Scene View and not in the Game View?
like mentioned, I can see it working with the cubes in the scene, but not the inserted prefabs. Ive tried it in CS now, its the same.