Ok, I tried explaining this before, but it seemed hard to explain and not many people understood what I was trying to do. I'm hoping this image will help, but honestly, I'm not optimistic.

In the above image you can see my problem. In my screen shot on the right hand side are two cubes - the front most one is controllable by the player and is raycasting forward. If the ray hits an object it can be picked up and moved around. However, in order for the ray to hit the crate behind it (the one slightly to its left), it needs to be held in the position shown because of the way the camera perspective works.
Obviously this isn't very user freiendly (they have to try and work out how far to either side to move the object to pick it up) so I want the ray being cast from the object to move forward from the main cameras perspective rather than in worldspace - thus allowing you to pick up an object that appears directly behind you when you play the game.
Please tell me if you need anything clarified and I'll do my best, but even trying to explain this much has given me trouble.
Anyway, here is my code so far (in java, attached to the controllable raycasting cube:
var hasObject: boolean = false;
var otherThing: Transform;
function Update () {
var fwd = Camera.main.transform.forward;
var hit : RaycastHit;
//only finds objects in the 'moveable' layer
var LayerMask = 1 << 9;
if (Input.GetButtonDown ("Fire2"))
{
if (!hasObject)
{
//if (otherThing){
if (Physics.Raycast(transform.position, fwd, hit, 50, LayerMask))
//if (Physics.Raycast(ray, hit, 50, LayerMask))
{
otherThing = hit.transform;
otherThing.rigidbody.isKinematic = true;
otherThing.parent = transform;
otherThing.Find("Glowblock").light.enabled = true;
hasObject = true;
print("Picked up "+otherThing.gameObject.name+"
");
}else
{
print("Nothing to pickup!
");
}
} else
{
otherThing.rigidbody.isKinematic = false;
transform.DetachChildren();
otherThing.Find("Glowblock").light.enabled = false;
hasObject = false;
print("Dropped "+otherThing.gameObject.name+"
")
}
}
}
can you clarify? post more screenshots. the second diagram doesn't look correct to me. Perhaps you can explain it's shape...
– loopyllamaI'll post more screenshots later. The second diagram is meant to show how the camera perspective looks when you play the game, as it narrows to a point in the distance.
– anon38117566