- Home /
Question by
levi6706 · Mar 18, 2021 at 02:57 PM ·
raycastgameobjectsspawningraycasthit
place a object not in a object
i have a place script with is simple it just place a object where the raycast hit is but idk how to not make a 1 by 1 cube spawn in the ground
do you use hit.normal cause im using hit.point
heres what the script look like
private void Place()
{
Ray ray = new Ray(_playerCamera.transform.position, _playerCamera.transform.forward);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, LookDistance, W_PlaceOn) && hit.collider != null)
{
if (W_Selected != null && hit.collider.gameObject != W_Selected)
{
W_Selected.transform.parent = null;
W_Selected.transform.localScale = Vector3.one;
W_Selected.transform.position = hit.point;
W_Selected.transform.rotation = Quaternion.LookRotation(hit.normal);
Inventroy.Remove(W_Selected);
}
}
}
image-2021-03-18-095425.png
(8.6 kB)
Comment
I think you would use hit point, but you have to offset it by 1/2 the height of the gameobject. And you may need to orientate it.
wait the thing im placing or the thing im placing it on??
Your answer
![](https://koobas.hobune.stream/wayback/20220613030920im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Problem With Raycasthit Angle 0 Answers
Something fishy with RaycastHit 1 Answer
How can I can I cast a ray from a gameobject? 1 Answer
Fall collision force with help of raycast 0 Answers
RayCast2d Not colliding with objects in other layers 1 Answer