Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 gilgada · Jan 04, 2012 at 11:59 PM · collisiongravityforcekinematiccatapult

Stopping objects with colliding with similar objects.

In my catapult game the player has to launch a projectile at a castle wall. The wall is made up of several bricks. These bricks are all flush to each other and do not intersect. Currently they have no rigid body attached so launching a test projectile at them would not do anything to move them. The problem comes with attaching a rigid body. Regardless of gravity, if they are not kinematic, they will collide with one another and before the projectile is launched the castle bricks will be thrown around the level. On the other hand, if they are kinematic, this means they can not be affected by the projectile, only by script.

Is there a way to tell them not to detect collisions against objects of a certain tag? Or perhaps to apply a script when the object with projectile tag has collided with them?

Currently my projectile is only fired by the motion of the catapult arm and therefore moves very slowly (increasing the motion speed would simply make the projectile clip through it. No scripts are being used to determine the momentum of the projectile but eventually there will be a calculation.

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
2
Best Answer

Answer by syclamoth · Jan 05, 2012 at 01:23 AM

Yes, it's easy enough to stop them from colliding with each other- just put them all on the same layer, and use Layer Based Collision to prevent that layer from colliding with itself.

However, if you do this, your entire castle will collapse as soon as the game begins! The actual problem is because of the way colliders interact with one another. First off, you should have some kind of script which automatically puts all the rigidbodies in the wall to sleep, so that they won't do anything until they are acted on by an outside force (i.e, the boulder). You may also want to increase the Physics settings' solver iteration count (this will make the simulation more stable).

Another thing- you really shouldn't be relying on physics to throw your catapult projectile. A better way to make it realistic (with minimal complicated maths on your part) would be to have the arm connected to the 'cradle' by a hinge joint, make the projectile a kinematic rigidbody that is a child of the cradle and then manually calculate the boulder's velocity one frame before you would have thrown it. Then, unchild it from the catapault, set it to non-kinematic, and manually set its velocity to the correct value! Then, you won't have to worry about the projectile falling through the catapult arm.

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 gilgada · Jan 05, 2012 at 01:37 AM 0
Share

thanks for the advice, I had tried hinge joints before but couldn't get it working. I would love to stay away from them in all honesty. Do you know how I can set the rigidbodies to sleep? Would it be in a script? Also, how would I unchild the projectile using code? And how about setting it to non-kinematic? Sorry for the influx of questions, but your answer has left me intrigued.

avatar image syclamoth · Jan 05, 2012 at 01:57 AM 1
Share

All of this stuff can be done in code, yes. How much coding experience do you have? I think you'll find that it's actually impossible to make a functional game without having at least some knowledge of the systems that make it all work.

For rigidbodies, sleep them using rigidbody.Sleep. To unchild something, just use

 transform.parent = null;

and setting a rigidbody to kinematic or otherwise:

 rigidbody.is$$anonymous$$inematic = true;
 rigidbody.is$$anonymous$$inematic = false;

I should mention that this stuff is really basic. If you don't know how to do these things already, you should work on something simpler until you are more familiar with the environment.

avatar image gilgada · Jan 05, 2012 at 02:03 AM 0
Share

thanks for the help :) I am very new to unity and javascript. This is part of my second year of my games course at university and we are expected to learn from doing, hence my need for solutions to some of my problems. I'm progressing slowly with unity and can't really start a simpler project until the module is over.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Setting limits to my trajectory 2 Answers

Firing projectile in curve 1 Answer

How to hit gameobjects to go into the opposite direction of hit? 1 Answer

Kinematic RigidBody2D as Player Object? 0 Answers

Object gravity but no collisions 0 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