Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by Alienjesus · Feb 28, 2011 at 09:54 PM · movementgameobjectraycastcollidertrigger

Moving objects using raycasting?

OK, so earlier I posted a question about trigger colliders which were recommended to me for my game. Basically, i want to be able to move a background object using the position of a game object in the foreground. Previously I had a cube in the foreground with a long box trigger attached to it to interact with objects in the background, the idea being that when objects activated its triggerStay, I could then trigger code to allow that object to me moved as a child of the foreground object.

However, I've had some issues with this (such as objects not being found despite having a rigidbody and collider) and was wondering whether it might be possible to do it with a raycast instead. Here's what I want to know.

  1. The box collider caused problems because of the camera perspective - perspective viewpoints caused trouble because the boc collider would extend to a central point in the distance, meaning the placement of my foreground object didnt directly correspond to what it could pick up. I was wondering if a Raycast would go directly forward in terms of screen position instead of worldposition so I could avoid this. (If this is possible with a trigger i'd like to know too!)

  2. How would I make my Raycaster's origin move with the gameobject i want to cast from? Is it as simple as including the raycaster as a script on that object or on a child of that object?

P.S. I know a mouse is a better way to do what I'm describing, but this is for a degree project game that relies on a physical method of control so that's not an option for me right now.

Thanks, if I've made this a bit confusing please tell me and I'll try to elaborate it a bit clearer. I am a newbie when it comes to Unity, so these might be half understood ideas that dont make sense to you experienced users

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

1 Reply

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

Answer by Alec-Slayden · Feb 28, 2011 at 11:34 PM

you can get the screen point of an object using WorldToScreenPoint

and raycasts can go from any 2 points that you'd like, or make a ray from the screenpoint of that object position with a certain length. A ray as such should go directly away from the screen, rather than being distorted by perspective.

EDIT: If you wanted perspective to be gone as a whole you could use a camera with orthographic projection

Comment
Add comment · Show 3 · 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 Alienjesus · Mar 01, 2011 at 08:10 AM 0
Share

Thank you, this is very helpful I'll try it now.

As for the orthographic camera thing, I tried it before but it doesn't work for what I need it for - the lack of the disappearing point in the distance was very helpful but unfortunately I need to have a sense of perspective that is completey lost with the orthographic camera - I will be moving objects from the distance to the foreground, so theyed need to change sizes to reflect this. Whilst my manipulation of the environment and the movement of the game environment are locked to 2D, my game environment needs to be fully 3D.

avatar image Alienjesus · Mar 01, 2011 at 08:17 AM 0
Share

Sorry to double comment, but if I'm right this should only find one object at each point right? It'll only find the foremost object in the scene at that screenpoint? If so, this is perfect and exactly what I needed!

avatar image Alec-Slayden · Mar 01, 2011 at 08:49 AM 0
Share

It should find the first collider the ray hits.

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

No one has followed this question yet.

Related Questions

Prevent shooting when gun is inside wall 1 Answer

Help with collision detection with specific colliders 1 Answer

active script from distance 3 Answers

Child collider triggering parent collider effects. 1 Answer

Trigger can't see the enemy 2 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