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
0
Question by jeremypagden · Apr 02, 2014 at 04:21 PM · coordinatescoverconstrainsticky

How can I make my player 'stick' to a fixed object

Hi, I am experimenting with a cover system for an FPS. Although it seems to be a VERY common question, and there are hundreds of references to such a system, nothing actually matches my particular requirements :(

I have a simple movement script and a simple CoverDetect script. The CoverDetect script casts a ray out from the front of my Player, and returns a RayCastHit object and two variables indicating that cover is possible and the type of cover. For example, some objects in my level are tagged as "CoverStanding". In other words, my player can enter cover behind this object while remaining in a standing position. I have other objects similarly tagged: "CoverCrouch" and "CoverProne". As my player explores the map, the CoverDetect script correctly identifies each object as one of the three cover types (by displaying it in GUIText).

When the player object is in a potential cover position and the user presses space, I want to constrain the movement of player object to plane of the object that the CoverDetect script has returned.

I have tried two techniques - both have failed:

  1. I simply set the tranform.z to zero. This actually works quite well, but only for cover objects oriented exactly to the World Coordinates.

  2. I've dynamically created a FixedJoint and joined the two rigid bodies together. This results in the player simply 'picking up' the cover object and walking around with it! Not quite what I intended LOL.

My guess is that I need to match the player coordinate system to the local coordinate system of the object returned by the CoverDetect script and then proceed from there - however, I have not been able to find any help on how to do this.

Let me thank you all for your patience - please forgive me if this has already been documented somewhere else - I have searched extensively I promise :)

Your assistance is much appreciated.

PS. Because my searching on this topic has been so frustrating, once I have cracked the problem, I intend to document it myself and make it available to the community.

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 Lo0NuhtiK · Apr 02, 2014 at 04:23 PM 0
Share

http://answers.unity3d.com/questions/142103/how-to-set-the-bounds-of-movement-for-one-object-t.html

1 Reply

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

Answer by robertbu · Apr 02, 2014 at 04:54 PM

Without source, I have to be a bit hand-wavy. I'm looking at the core of your question as:

I want to constrain the movement of player object to plane of the object that the CoverDetect script has returned.

It can be done arbitrarily, but it is likely easiest done using the transform of the cover object. And it make it much easier if the normal to the plane of movement is always the same local axis. Say you want to allow the object to move along the x and y of the cover object, but not the local z, and you have the proposed move direction:

 moveDir = coverObject.InverseTransformDirection(moveDir);
 moveDir.z = 0.0;
 moveDir = coverObject.TransformDirection(moveDir);

You convert the move direction into the local coordinates of your cover object, eliminate one axis of movement and then convert it back.

Comment
Add comment · Show 1 · 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 jeremypagden · Apr 03, 2014 at 08:37 AM 0
Share

@robertbu - $$anonymous$$y apologies for not posting the source code - however, what I have now is so simple and so standard there seemed little point in posting it.

And in fact a little bit hand-wavy is perfect by me!

Thank you for your quick response. I believe this is exactly what I need - but will test it in the next few hours.

I'll post my results as soon as possible.

@Lo0Nuhti$$anonymous$$ Thanks for your reply as well

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

21 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

Related Questions

Screen Coordinates of an object's corners 2 Answers

Instantiate and destroy on given location 1 Answer

Scene View - Left-Hand XYZ Coordinates 1 Answer

world and local locations.. 1 Answer

Converting iPhone touch to world coordinates 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