- Home /
Pulling a vector 3 back?
I have a raycast that when hits a brick, it deleted, or places. vut it places inside of the exitigng brick. how would I make it so that the hit place is actualy closer to the placer? like .1 vector closer.
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hits : RaycastHit;
if(Physics.Raycast(ray,hits,500)){
if(hits.distance > 1){
Debug.Log("YUS");
amount = amount + 1;
var hitss : Vector3;
hitss = hits.point;
This is really just it. it instantiates a brick where I t hits, then it rounds to the nearest 1vector on the grid.
Answer by robertbu · May 05, 2014 at 01:39 PM
You can either back it up using the hit.normal:
var hitss = hit.point + hit.normal * someValue;
...or you can reverse the direction used in the raycast:
var hitss = hit.point - ray.direction * someValue;
'someValue' is either a variable or a constant indicating how var you want to back it up. For what I think you mean by "1 vector closer," replace with 1.0.
A normal is a vector pointing perpendicular to a surface. Each arrow in the following image is the normal at that point on the surface:
Your answer
![](https://koobas.hobune.stream/wayback/20220613144310im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to get an offset of a RaycastHit? 0 Answers
Get the position of the first finger that touched the collider? 1 Answer
Why multiply a vector by -2? 1 Answer
How to Spherecast/Raycast diagonally? 1 Answer
Raycast Mouse Position To vector3 1 Answer