- Home /
Raycasting in the direction of a target but with a fixed angle to the ground
Hello, I seem to be in a bit of a pickle with a piece of code. I have a click-to-move Character and I'm trying to check if there is a ground-gap right next to my character, in the direction of target/click-position.. I'm using :
Vector3 downwards45 = ( Vector3.forward - Vector3.up).normalized;
the angle to ground is great but as you can imagine, it's not considering the target/click position..
Vector3 targetDir = target.transform.position - this.transform.position;
Vector3 downwards45 = (targetDir - Vector3.up);
it almost works but the angle to ground is not fixed, but rather depends on the target position..
Help would be much appreciated.. thanks
Answer by Laurentino · Mar 08, 2018 at 09:13 AM
Instead of Vector3.forward you could either use the forward vector of your character (YourCharacter.transform.forward) or calculate the vector that describes the direction from your character to the target/click-position (Target - YourCharacter.transform.position).
the script is on my character, and targetDir = target.transform.position - this.transform.position; besides, this doesn't even consider my question which is to have an angle to the ground independent to the character/gameObject own rotation. :(
Your answer
![](https://koobas.hobune.stream/wayback/20220612154143im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Raycast in the direction of looking plus an angle offset 0 Answers
Problem With Raycasthit Angle 0 Answers
Check if player is in front of enemy? 4 Answers
How to calculate direction between 2 objects 2 Answers
Detect touch location? 1 Answer