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 Ricewind1 · Nov 05, 2014 at 12:47 AM · collisionmovementgravitygameobjects

Object "crawling" over floor, how?

For my game I'd like to have magic spells that crawl across the surface. Meaning specifically that they can move uphill/downhill and up/down slopes (but nothing too steep such as 60 degree + angles. Can't have them crawling up against walls or boundaries).

The problem is that the spell needs to be able to go through enemies and certain objects. If I set the collision to "Is Trigger" the spell will fall through the floor.

How can I get it to:

  1. Move along the surface

  2. Not fall/move through the surface

Comment
Add comment · Show 2
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 AlwaysSunny · Nov 05, 2014 at 12:53 AM 0
Share

Is there a good reason you're using rigidbody physics to drive your "projectile"? If you want to use that approach, you could feasibly solve the issue by separating your respective objects into different layers. Only let the projectile physically interact with the ground, and have a secondary trigger collider on the projectile which only reacts to things the projectile can affect.

avatar image Ricewind1 · Nov 05, 2014 at 02:18 AM 0
Share

No, I just don't know how else to move something across the floor. Do you have a better suggestion? And how would collision with specific layers work in code? Do you have a reference to unity docs?

2 Replies

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

Answer by Ricewind1 · Nov 05, 2014 at 05:08 AM

I Managed to resolve this issue but I'm not very happy with it. It works however. Let me explain how I achieved this for anyone who needs it for future reference.

I started out by making a cude, adding a ridgidbody, and material set to ice (to that it can slide). On instantiating the floor is automatically located. It's moved by rigidbody.addforce. Rotation is locked for x y and z (else the visual aspects of the spell will look strange). To prevent it from flying I've made an IsGrounded method that looks if there's an object between the cubes position and 10 away. If there is, the cube is moved to that position (+ offset) if there isn't the object is destroyed (prevents falling off map etc). The above 'sticks' the cube to the surface.

For collision I did the following: I created 2 new layers, a spellLayer and a LevelLayer. The levellayer is basically every surface. The spelllayer only collides with the levellayer. (Project settings > Physics). The cube gets the spelllayer.

Next I created an empty gameobject as the child of the cube. Added a boxcollider to this, and added a collision method. (Box collider to istrigger).

Since I can only add a "spell" class to my magic weapons I made both the cube and the child a spell. On start I copy all the required data from the cube to the child.

The method below is on the child and basically checks for many targets have been hit and destroys it if the maxhits is exeeded. The cube is destroyed after a set amount of time (based on the max distance it may travel).

As I said, it works, but it seems a bit sloppy. I will try to improve this if possible. Feel free to leave a comment.

     public void HitsCount()
     {
         if (this.MaxTargets < 0)
         { return; }
 
         Currenthits++;
         if (Currenthits >= this.MaxTargets)
         {
             Destroy(transform.parent.gameObject);
         }
     }
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
avatar image
-1

Answer by Steampunk_Droid · Nov 05, 2014 at 12:58 AM

"Is Trigger" disables collisions, if you want it to not collide with enemies and certain objects try using this: http://docs.unity3d.com/ScriptReference/Physics.IgnoreCollision.html

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 Ricewind1 · Nov 05, 2014 at 01:05 AM 0
Share

Is trigger doesn't disable collision. In fact, "is trigger" is default for projectiles hitting rigid-bodies to prevent them from moving (if unwanted). The main problem is getting it to move across the surface while is trigger is enabled.

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

28 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

Related Questions

Can't get gravity to work proberly (transform) 2 Answers

Disabling gravity when colliding with the terrain? 0 Answers

Stopping objects with colliding with similar objects. 1 Answer

Jumping and reverse gravity with a Rigidbody2D (based on the Ruby tutorials) 1 Answer

How to move a Game Object from a script not attached to it. 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