New answers tagged

0

I am not aware of an easy way of doing this. The way I'd do this is the following: Determine XY position of click on texture (x = 0..1, y = 0..1) How to do this depends on where you use it, but will likely require raycasting. Go to the camera that sends the image to the texture. Assuming the camera uses perspective projection: Calculate the 3D ...


1

Rigidbody Contraints is a class to use for the rigidbody. In your case, instead of using hit.transform. = RigidbodyConstraints.FreezeRotation;, I would replace that with hit.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeRotation;I see that you have tried to set a Rigidbody class on a Transform. Rigidbody constraints take a ...


0

As DMGregory has pointed out in the comment, you can use SphereCast instead. A spherecast works a lot like a raycast, only that instead of checking for hits in a single line, it has a 'radius' parameter which defines the size of the sphere, effectively making it behave like a thick ray. Example: RaycastHit hit; if(Physics.SphereCast(transform.position, ...


0

The only solution I can think of is to use two or more raycasts that are placed close together but not in the same position. That way if one misses due to a mesh seam, the other should hit.


2

Pixel picking is effective if you need to do lots of raycasts from one source. You bear the overhead of rendering and readback once, then get all your many picks at low incremental cost each. To get just one ray result you've already had to calculate thousands or millions whether you use them or not. If you're only doing a few raycasts at a time (say a ...


0

Looks like you need to restrict the euler angles of the turret, after the quaternion rotation has been effected. basically you'd just do something like: transform.localEulerAngles = new Vector3(transform.localEulerAngles.x < 0 ? 0 : transform.localEulerAngles.x, transform.localEulerAngles.y, transform.localEulerAngles.z); ...I think X is the right axis ...



Top 50 recent answers are included