|
Hello, I am trying to make a 3rd person camera script. But it does not work and I don't know what I am doing wrong. First the explanation: There is a far-cam-point, this is the max distance between player and camera. The close cam point is the same with z=0. If the camera hits a wall, I just need to apply the (negative) distance between the closecampoint and the hit of the raycast to z of farcampoint and can then set the cam position to this new farcampoint. I draw Debug-Lines all over here: Cyan is farcampoint to closecampoint. Yellow is closecampoint to hit and red is the raycast itself. All lines are aligned over each other, so that is fine. But it doesnt seem to hit anything when I approach a wall. Any help with this would be great. (Ah, yes...lerp and slerp will come later... ;) ) Here is the code: //[new] Vector3 farCamPoint = player.position + camYRotation * pivotOffset+ aimRotation * camOffset; Vector3 closeCamOffset=new Vector3(camOffset.x, camOffset.y, 0.0f); Vector3 closeCamPoint= player.position+camYRotation*pivotOffset+aimRotation*closeCamOffset;
(comments are locked)
|
|
[Solved] It was the mask as you mentioned. I just copied it from the camera script in the 3rdPersonShooter example where it is also used for aiming at stuff. (Thats done in another script by me..) so, set the mask to everything and it works. and it works... (not really tested yet but it already moves the camera...anywhere...hope its the right spot..i got another ray just now, hope it works with the ray above. ;) ) Yay it works. You're free to use it yourself ;)
May 23 '12 at 10:42 AM
ben0bi
The other vars are: camOffset: the maximum camera offset from pivotoffset...and pivotOffset: the offset from the player-Transform.
May 23 '12 at 10:43 AM
ben0bi
For future use case, you may want to consider making the mask variable declaration public. If you do so, you can view the mask in the inspector, and it will have a drop down check list like it does on any Camera where you can set the layers there. I find this method a lot easier than having to deal with bitwise statements.
May 23 '12 at 07:01 PM
dannyskim
(comments are locked)
|

Do the walls have colliders on them? And are they in layers which are not excluded from raycasting?
Also, how are you declaring your layerMask? Is it a public variable? Did you construct a bitwise statement yourself?
How is it behaving currently?
There is a Transform called "player" where the camera turns around.
This is how the mask is created, I think it should only exclude the player and nothing else - not?
And yes, the walls have colliders. I tried it with box-collided walls and with a mesh collider for a whole house, nothing works.
Here is the mask code: