Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by LifeSymbiont · Jul 26, 2016 at 06:30 PM · console.log

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.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image NoseKills · Jul 27, 2016 at 06:48 AM 0
Share

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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");
     }
Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image LifeSymbiont · Jul 27, 2016 at 08:27 AM 0
Share

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.

avatar image NoseKills · Jul 27, 2016 at 09:43 AM 1
Share

@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

avatar image LifeSymbiont NoseKills · Jul 27, 2016 at 10:25 AM 0
Share

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 =)

avatar image NoseKills LifeSymbiont · Jul 28, 2016 at 05:32 AM 0
Share

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.

You can read up on vector math basics for example here

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

64 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges