Console does not Debug.Log - all 3 Icons are activated
Hey guys, I have a little problem with my script, it seems to be impossible to let my first step of an Gravitationsystem Debug.Log the testmessage so that I can see that the Raycast between my Planet and the Player is working. Becouse nothing is showing up I cant test it. here you have the code:
var Player : GameObject;
var Planet : GameObject;
var hit : RaycastHit;
var ray : Ray;
function Update() {
Raycast = GraviRay = new Ray(Planet.transform.position, Player.transform.position);
if (GraviRay == true){
Debug.Log("Gravitation activated");
}
}
Any help for the Script would be good. And btw... my 3 icons on the upper right of the console are marked. So that would not be the problem.
You are not raycasting anywhere in this code. You are just creating a ray object and storing it in 2 variables (that are not defined)
Also the second parameter of the Ray constructor should be the direction, not endpoint of the ray
Answer by Jessespike · Jul 26, 2016 at 06:40 PM
You should see 2 errors at least.
Raycast and GraviRay are being used as variables, but they are not declared anywhere.
Maybe you wanted something like this instead:
ray = new Ray(Planet.transform.position, Player.transform.position);
if (Physics.Raycast(ray)){
Debug.Log("Gravitation activated");
}
Well, I believe that the script fix you gave me should work perfectly. But my console is just blank, there were no errors before... just NOTHING :C So I need some more help.
@Cortex00 The second parameter of Ray constructor should be direction, so probably
ray = new Ray(Planet.transform.position,
Player.transform.position - Planet.transform.position);
Also if the planet has a collider, the ray might always collide with it ins$$anonymous$$d of player since the ray starts from inside the planet
Thank you, it finally worked, Btw. I just wanted to know why you put the Planet.transform.position again after the player.transform.position one... Becouse it doesnt make sense to have a working script wich you not fully unterstand. I am in learning a process =)
The first parameter in new Ray(a, b)
is the point where the ray should start. The second parameter is the direction we should raycast to.
With vectors, just like with normal numbers you get the direction by subtracting starting point from end point
A B C
●•••●•••••●
0 4 10
The distance and from B to C is 10-4=6 and the direction is positive. The distance from C to B is B-C=-6. The same goes with vectors. PlayerPosition-PlanetPosition=vector from planet to player.
Your answer
Follow this Question
Related Questions
possible to ping project asset on log click ? 0 Answers
Compiler Error, Cannot Go Into Playmode 2 Answers
[HELP] No info shows up in the console! 0 Answers
Are Debug.Log calls and errors displayed in the console in chronological order? 1 Answer
For end users do console errors and messages generate when they play the game ? 1 Answer