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 Datester35 · May 07, 2014 at 12:59 PM · gameobjectcollideasteroidmine

How do you make a type of excavation when a gameobject collides with another gameobject?

I am making a sort of space sim. In my game, you control a ship and I need to figure out how to make it so that you fire projectile rigidbody spheres at cube-like meshes (with rigidbodies?), that are "asteroids". How can I make it so that when you shoot at one of these meshes, it has an indent at where you shot, and can eventually fully disappear when you have shot it enough. This should be somewhat like in space engineers.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Kacheek · May 07, 2014 at 02:37 PM

well this is a bit more complex since youre actually asking several questions ...

fire a sphere projectile

first create the sphere you want to shoot than save it as a prefab you can than spawn it with Object.Instantiate ( see https://docs.unity3d.com/Documentation/ScriptReference/Object.Instantiate.html)

so when you click you should execute that instantiate command of course include the position where you want it to spawn (in front of your blaster i guess ?) and assign the sphere prefab to it

you will then at first only have a sphere in front of your blaster i would suggest to use Force to let the sphere move (https://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.AddForce.html)

also dont forget to turn off "Usergravity" since you are in space theres no gravity! it will fall down if you dont do that.

the sphere and your cube asteriod should both have rigidbodys with no gravity andn both should have colliders that match their appearance!

you should also assign a proper mass for example an asteroid may weight up to some tons! the mass field of the rigidbody component is the objects weight in kg also keep in mind if you let your blaster sphere only have a mass of 1 and the asteroid has 1000000 it wont affect the asteroid it should be something like 10 and 100 i think... (just a guess you will ahve to experiment with different values)

so now you have a blaster that gets shot and it may hit the asteroid and both will move properly afterwards the indent is kinda complex so i skip this for now

for it to dissapper you could assign hp to it and if it gets hit it will lose 1 hp each so if you hit it lets say 3 times it will be destroyed

the indent thing could be done with adding bones to your cube mesh and move each bones or something i dont know an easy way for that sorry

i hope i could help you a bit

best regards

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 Datester35 · May 07, 2014 at 04:59 PM 0
Share

That seems to have answer most of my question, but do you know how I can use bones to make indents? It seems very simple, yet I can't quite grasp it.

avatar image Kacheek · May 08, 2014 at 10:32 AM 0
Share

let the asteroids bone that is the closest to the colliding point with your projectile move inverted to the center of your asteroidd object for a certain amount or just do

     if(boneishit)
 {
     bonetransform.localposition = new Vector3 (0,0,0);
 }

this will let it move to the actual center of it i think it will get invisible if you hit all bones too just try it out ;)

but well it my look strange

avatar image Kacheek · May 08, 2014 at 10:55 AM 0
Share

but a better looking solution would be to do this here:

this will make a smoth movement of the bone if it gets hit towards the center and will stop if its halfway to the center

should look better

if you got issues understanding this code check

https://docs.unity3d.com/Documentation/ScriptReference/Vector3.Lerp.html

 Vector3 startposition;
 Vector3 newposition;
 bool boneIsHIT = false;
 
 float journeyLength = 0f;
 float distCovered = 0f;
 float fracJourney = 1f;
 
 float speed = 1f;
 float startTime = 0f;
 
 void start()
 
 {
 
 
 
 }
 
 
 void Update ()
 {
 // if you set speed to 1 it will move 1unit per sec
 
 
 if(boneIsHit)
 {
 boneIsHit = false;
 //this should only be executed once!
 startposition = bonetransform.position;
 // we dont want it to move to the center so we half the difference
 // and take it the half away so we only move half towards the 
 // center
 newposition = cubetransform.position - 
 (Vector3.Distance(cubetransform.position,bonetransform.position) / 2);
 
 // $$anonymous$$eep a note of the time the movement started.
         startTime = Time.time;
         
 // Calculate the journey length.
         journeyLength = Vector3.Distance(startposition, newposition);
 }
 // Distance moved = time * speed.
     distCovered = (Time.time - startTime) * speed;
         
 // Fraction of journey completed = current distance divided by total distance.
         fracJourney = distCovered / journeyLength;
 
 if(fracJourney <= 1)
 {
 bonetransform.position = Vector3.Lerp(start$$anonymous$$arker.position, end$$anonymous$$arker.position, fracJourney);
 }
 }
avatar image
0

Answer by ncortiz · Jul 15, 2014 at 04:40 PM

http://u3d.as/content/mike-mahoney/meshinator-realtime-mesh-deformation/4vC

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

22 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

Related Questions

Help touch button 1 Answer

onTriggerEnter accesing gameObject components 1 Answer

How to make a GameObject that collides but the player can go through it? 2 Answers

Create a Proximity Mine 1 Answer

using Contains(gameObject) to find and destroy a gameObject from a list 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