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 /
avatar image
0
Question by Mrroundtree22 · Mar 20, 2019 at 11:30 AM · raycastaxisanglereflectiondot

Player transform should always be zero

alt text

The problem that I am having is that I want to calculate the angle between my raycasts origin (the player) and the hit.point. I want my player to shoot a ray which is always at 0 degrees regardless where they stand in worldspace but this isn't happening (as shown above).

paint2.jpg (36.0 kB)
Comment
Add comment · Show 4
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 TreyH · Mar 20, 2019 at 01:36 PM 0
Share

It's hard to tell what you mean by "Transform should be zero", and "shoot a ray which is always at 0 degrees". Degrees relative to what? Transforms aren't values, you can think of them as triplets deter$$anonymous$$ing an object's position, orientation, and scale in the world.

Are you trying to shoot the ray in a straight line ins$$anonymous$$d of from the player's position?

avatar image Mrroundtree22 TreyH · Mar 20, 2019 at 01:49 PM 0
Share

What I mean is that the raycasts position (the raycast shoots out from the players transform.forward), regardless of where the player is standing in worldspace, should always be 0 degrees so that when it hits the surface of a gameobject it calculates the angles between 0 and whatever angle the gameobject has. As it is now it calculates the players place in worldspace as well which is wrong. I know it is hard to explain but do I make some sense? Is the picture helping?

avatar image TreyH Mrroundtree22 · Mar 20, 2019 at 01:52 PM 0
Share

It might be easier to just link your code? Unity doesn't force raycasts to shoot out from a transform's position along its forward vector, so you are telling it to do that somewhere.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Mrroundtree22 · Mar 20, 2019 at 02:03 PM

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class ProjectileReflection : MonoBehaviour {
 
     public int maxReflectionCount = 5;
     public float maxStepDistance = 200;
 
     private float angle = 0;
 
     // Use this for initialization
     void Start () {
         
     }
     
     // Update is called once per frame
     void Update () {
         
     }
 
     void OnDrawGizmos()
     {
         DrawPredictedReflectionPattern (this.transform.position + this.transform.forward * 0.75f, this.transform.forward, maxReflectionCount);
     }
 
     void DrawPredictedReflectionPattern(Vector3 position, Vector3 direction, int reflectionsRemaining)
     {
         if (reflectionsRemaining == 0)
             return;
         Vector3 startingPosition = position;
 
 
         Ray ray = new Ray (position, direction);
         RaycastHit hit;
         if (Physics.Raycast (ray, out hit, maxStepDistance)) 
         {
             direction = Vector3.Reflect (direction, hit.normal);
             position = hit.point;
             angle = Vector3.Angle (startingPosition, position);
 
             print (angle);
 
 
         }
         else
         {
             position += direction * maxStepDistance;
         }
 
         Gizmos.color = Color.yellow;
         Gizmos.DrawLine (startingPosition , position);
 
         DrawPredictedReflectionPattern (position, direction, reflectionsRemaining - 1);
     }
 }

This is the reflection script I got. I want to check the angle of the origin of the ray (which I want to always be 0) + the angle of the hit.point (position).

Comment
Add comment · 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

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

145 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 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 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

Reflection based on angle 0 Answers

Get angle from Object to nearest point of other Object 0 Answers

2d Raycasting, trouble drawing rays at the correct angles 1 Answer

2D : Rotation of Object With x-y Axis 2 Answers

Set Quaternion to another Quaternion, but oriented along 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