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 Stuntrally · Oct 28, 2012 at 03:04 PM · javascriptfpscontrollerdetonator

FPS Controller and Explosion?

I'm using the detonator framework and have an fps controller that can't be affected by the explosion. I have written this script so far so that the player can be moved:

 var targetObj : Transform;
 var prefabContainer:Transform;
 var proximity : float = 8;
 
 function Update() {
 
     var dist = Vector3.Distance(targetObj.transform.position, transform.position);
   if (dist < proximity) {
     var instanceContain = Instantiate(prefabContainer, targetObj.transform.position, targetObj.transform.rotation);
     targetObj.transform.parent = instanceContain;
     
     }
  }


But unity doesn't allow prefab objects to be parented. How do I set targetObj to be a specific item in the hierarchy and not a prefab?

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
1

Answer by deltamish · Oct 28, 2012 at 03:18 PM

Hai found your problem

use

targetObj.transform.parent = instanceContain.transform;

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 Stuntrally · Oct 28, 2012 at 05:56 PM 0
Share

I get this error:

Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption. UnityEngine.Transform:set_parent(Transform) PlayerExplosion:Update() (at Assets/PlayerExplosion.js:10)

avatar image deltamish · Oct 29, 2012 at 05:17 AM 0
Share

Hmm what is instanceContain and targetObj

why do you want to parent them to add explosion

avatar image Stuntrally · Oct 29, 2012 at 11:19 AM 0
Share

I'm trying to parent the charactercontroller (targetObj) into a container with a rigidbody (instanceContain) so that it is affected by the explosion.

avatar image
1

Answer by deltamish · Nov 01, 2012 at 11:38 AM

Hi, sorry for the late reply I was quite busy You can 1.Create a empty gameobject and child the player obj.Remove Charactercontroller .Add rigidbody ,Use rigidbody.velocity instead of CharacterController.Move to move the player

OR

  1. havent tried this yet Add this to your player prefab

    var exppos:Vector3; var self:Transform; var explode:boolean = false; var minexp:float = 5.0; var char:CharacterController; var expspeed:float = 12;

    function Explosion(pos:Vector3){ self = pos; explode = true; }

    function update(){ if(explode){ if(Vector3.Distance(self.position,exppos) < minexp){//checking second time that if player's pos is less than minimu explosion distance var direction = self.position - exppos;

    char.Move(direction.normalized expspeed Time.deltaTime);

    }else{explode = false;} } // your movement code }

In your explosion script add this

    var pos:Vector3;

 function Update(){
     var objs:Collider[] = 
  
     Physics.OverlapSphere(transform.position,9);
     
     for(var:exp in objs){
     if(exp.transform.tag =="Player"){
     exp.transform.SendMessage("Explosion",pos,SendMessageOption.DontRequireReceiver)
     ;}
     }
     }



Rate it if you like it

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

10 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

Related Questions

Detect explosion Character Controller 4 Answers

Changing FPSController values via C#? 1 Answer

Instantiating 1 Answer

calling a CS module from within Javascript 0 Answers

Setting Scroll View Width GUILayout 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