Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 DevoMage · Jul 19, 2015 at 07:00 PM · raycastlookatorbit

replace raycast with transform direction

i have working code here. i would like to replace the raycast with a more appropriate solution.

possible?

there will be 30-40 players all with this script on their player controller.

thanks in advance!

alt text


 using UnityEngine;
 
 //smoothly rotate a particle around a player 
 //at a set distance 
 //and magenetic to the target
 
 public class rotatedemo : MonoBehaviour
 {
     GameObject pointB;
     GameObject pointA;
 
     public float interval = 1.0f;
 
     void Start()
     {
         pointB = GameObject.Find("player");
         pointA = GameObject.Find("target");
 
         InvokeRepeating("Repeat", 0.01f, interval);
     }
 
     void Repeat()
     {
         //get a ray from point A in the direction of point B
         //http://answers.unity3d.com/questions/32532/how-to-find-direction-between-two-points.html
         Ray ray = new Ray(pointA.transform.position, (pointB.transform.position - pointA.transform.position).normalized);
 
         //move the sphere 2 units away from the target
         transform.position = ray.GetPoint(2);
 
         //rotate the sphere to look point B
         transform.LookAt(pointB.transform);
     }
 }


hierarchy.png (4.4 kB)
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 DevoMage · Jul 20, 2015 at 01:32 AM 0
Share

repeating a raycast every second for 40 players is a bit intense. is this the best solution or is there a better way without the raycast? all 30-40 players will not have this active at all times - but im trying to achieve the most efficient solution.

1 Reply

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

Answer by KdRWaylander · Jul 20, 2015 at 07:50 AM

Hi,

I don't know why you shoot this ray, since you compute the direction juste before.

Try setting the transform.forward of your sphere equal to your AB direction and then add +2 to the forward direction.

Then, you use LookAt to replace the sphere.

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

2 People are following this question.

avatar image avatar image

Related Questions

Indicator rotating around player 1 Answer

Raycast Third Person Camera Problem 4 Answers

Make character look at mouse position, not world position 3 Answers

Instantiate same PreFab to an array of GameObject by RayCast. 1 Answer

Best way to tell which object(s) are being looked at? 3 Answers


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