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 george3d2011 · Feb 06, 2013 at 04:16 PM · collisiontriggerturretfireball

how to make triger fireball not to pass through spesific objects

hey guys I am a begginer user of unity3d and i would like to learn how i can make fireballs which are shooted by my turrets (and are trigger) not to pass through spesific walls or grounds i have put.. so here is my scripts

Movement Script:

 //Moving Around
 var speed = 3.0;
 var rotateSpeed = 3.0;
 var mouserotationSpeed : float = 5.0;
 //Shooting
 var bullitPrefab:Transform;
 //Dying
 static var dead = false;
 //Getting Hit
 var tumbleSpeed = 800;
 var decreaseTime =.01;
 var decayTime = 0.01;
 static var gotHit = false;
 private var backup = [tumbleSpeed, decreaseTime, decayTime];
 //Jump
 var jumpSpeed : float = 8.0;
 var gravity : float = 5.0;
 
 function LateUpdate()
 {
 if(dead)
 {
 transform.position = Vector3(0,20,0);
 gameObject.Find("Main Camera").transform.position = Vector3(0,4,-10);
 dead = false;
 }
  
 if(gotHit)
 {
 if(tumbleSpeed < 1)
 {
 //we're not hit anymore... reset & get back in the game!
 tumbleSpeed = backup[0];
 decreaseTime = backup[1];
 decayTime = backup[2];
 gotHit = false;
  
 }
 else
 {
 //we're hit! Spin our character around
 transform.Rotate(0,tumbleSpeed * Time.deltaTime,0, Space.World);
 tumbleSpeed = tumbleSpeed - decreaseTime;
 decreaseTime += decayTime;
 }
 }
 }
 
 //function OnControllerColliderHit(hit:ControllerColliderHit)
 function OnTriggerEnter(hit : Collider)
 {
 if(hit.gameObject.tag == "fallout")
 {
 dead = true;
 HealthControl.LIVES -= 1;
 }
  
 if(hit.gameObject.tag == "enemyProjectile")
 {
 gotHit = true;
 HealthControl.HITS += 1;
 Destroy(hit.gameObject);
 }
 }
 
 function Update ()
 {
 var controller : CharacterController = GetComponent(CharacterController);
     if (controller.isGrounded) 
     {
         // We are grounded, so recalculate
         // move direction directly from axes
         moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,
                                 Input.GetAxis("Vertical"));
         moveDirection = transform.TransformDirection(moveDirection);
         moveDirection *= speed;
         transform.Rotate(Vector3(0, Input.GetAxis("Mouse X"), 0) * Time.deltaTime * mouserotationSpeed);
         
         if(Input.GetButton("Jump")) 
         {
             moveDirection.y = jumpSpeed;
         }
     }
 
     // Apply gravity
     moveDirection.y -= gravity * Time.deltaTime;
     
     // Move the controller
     controller.Move(moveDirection * Time.deltaTime);
 
 //shoting
 if(Input.GetButtonDown("Fire1"))
 {
 var bullit = Instantiate(bullitPrefab, transform.Find("Spawn").transform.position, Quaternion.identity);
 bullit.tag = "wormProjectile";
 bullit.rigidbody.AddForce(transform.forward * 3000);
 }
  
  if(transform.position.y < -200)
 {
 dead = true;
 HealthControl.LIVES -= 1;
 }
 }

  @script RequireComponent(CharacterController)

Turret Script:

 var distanceTillShoot : float;
 var LookAtTarget : Transform;
 var damp : float = 6.0;
 var bulletPrefab : GameObject;
 var savedTime = 0;
  
 function Update ()
 {
 if(LookAtTarget)
 {
 var rotate = Quaternion.LookRotation(LookAtTarget.position - transform.position);
 transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp);
 var seconds : int = Time.time;
 var oddeven = (seconds % 2);
 if(oddeven)
 Shoot(seconds);
 transform.LookAt(LookAtTarget);
 }
 }
 
 function Shoot(seconds)
 {
     if(seconds!=savedTime)
     {
         var bullet = Instantiate
 
 (bulletPrefab, transform.Find
 
 ("spawnPoint").transform.position, 
 
 Quaternion.identity);
         bullet.gameObject.tag = 
 
 "enemyProjectile";
         bullet.rigidbody.AddForce
 
 (transform.forward * 2500);
         
         savedTime=seconds;
     }
 }
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 iwaldrop · Feb 06, 2013 at 08:04 PM

Don't really need to see your code for this question (yet, anyway). In order to control physics collisions you need to both add layers (Inspector/Layer/Add Layers) and setup the collision matrix (Edit/Project Settings/Physics). Once you have a, lets call it 'Projectile' layer, you can control what 'Projectiles' will interact with by unchecking the corresponding box(es). This will prevent physics from even registering contact between the two layers, potentially improving performance over OnCollisionEnter and OnTriggerEnter conditionals.

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 george3d2011 · Feb 10, 2013 at 05:39 PM 0
Share

sorry but I am a begginer so, i can't understand what you want to tell me please will you explain me more?

avatar image
0

Answer by george3d2011 · Feb 09, 2013 at 12:21 PM

sorry but I am a begginer so, i can't understand what you want to tell me please will you explain me more?

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

Do a collider only with certain taged objects 2 Answers

Can't add Rigidbody component because collision prevents it 2 Answers

How do I make a character die when he fells. 1 Answer

Trigger respawn after collision? 3 Answers

My movement function with jump won't work with collider function 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