- Home /
How to add a value to a Raycast Vector
I have this script:
RaycastHit hitInfo;
if (Physics.Raycast(transform.position, Vector3.down, out hitInfo))
{
if (hitInfo.normal.y < SlideThreshold)
slideDirection = new Vector3(hitInfo.normal.x, -hitInfo.normal.y, hitInfo.normal.z);
}
if (slideDirection.magnitude < MaxControllableSlide)
MoveVector += slideDirection; //NO QUITAR EL + // NO SIRVE CON MENOS
else
{
MoveVector = slideDirection; // NO QUITAR // NO SIRVE CON MAS
}
How can I add a value to make it faster when it slides down? For example like this:
if (Physics.Raycast(transform.position, Vector3.down(0,-40,0), out hitInfo))
Is that posible??? How can I do it correctly???
Raycast and 'faster' do not compute for me. Are you asking how to make the object the Raycast hits move faster?
No, I am trying to make the sliding based on raycasthit go faster, but when i do it doesnt move in a diangonal direction, it kinda makes lots of jumps when sliding.
Just multiply the direction of the "sliding" by a scalar value. If you don't know how vectors work, I highly suggest you do. It's incredably helpfull.
Answer by frogsbo · Mar 16, 2014 at 07:19 PM
you have to use information between the player position and raycast hit position to make controlled values. make a vector3 arrow maths by delete target position from player position, you can then substract values onto that vector3.y. you use the distance of the 2 points as well for speed.
thanks. But can you be more specific? It is hard to understand if you dont put an example. Do you want me to put my code so you can edit it. Because I still dont know how to make what you said, although I understand it. It can have many interpretations.