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 Lewenos · Jan 25, 2012 at 08:52 PM · fps

How to change the speed of gameobject?

Hi guys, i have some problems with this script: (read down for why..)

     var cameraObject : GameObject;
  @HideInInspector
  var targetXRotation : float;
  @HideInInspector
  var targetYRotation : float;
  @HideInInspector
  var targetXRotationV : float;
  @HideInInspector 
 var targetYRotationV : float;
 
 var rotateSpeed : float = 0.3;
 
     var holdHeight : float = -0.5;
  var holdSide : float = 0.5;
  var racioHipHold : float = 1;
  var hipToAimSpeed : float = 0.1;
  @HideInInspector
  var racioHipHoldV : float;
 
 var aimRacio : float = 0.4;
 
 var zoomAngle : float = 30;
 
 

    var fireSpeed : float = 15;
  @HideInInspector
  var waitTilNextFire : float = 0;
  var bullet : GameObject;
  var bulletSpawn : GameObject;
 
     var shootAngleRandomizationAiming : float = 5;
  var shootAngleRandomizationNotAiming : float = 15;
 
 var recoilAmount : float = 0.5; 
 var recoilRecoverTime : float = 0.2;
  @HideInInspector
  var currentRecoilZPos : float;
  @HideInInspector
  var currentRecoilZPosV : float;
 
 var bulletSound : GameObject; 

 var muzzelFlash : GameObject;
 
 function Update () { 
 var holdMuzzelFlash : GameObject;
  var holdSound : GameObject;
  if (Input.GetButton("Fire1")) { 
 if (waitTilNextFire <= 0) { 
 

    if (bullet)
  Instantiate(bullet,bulletSpawn.transform.position, bulletSpawn.transform.rotation);
  if (bulletSound)
  holdSound = Instantiate(bulletSound, bulletSpawn.transform.position, bulletSpawn.transform.rotation);
  if (muzzelFlash)
  holdMuzzelFlash = Instantiate(muzzelFlash, bulletSpawn.transform.position, bulletSpawn.transform.rotation);
 
  targetXRotation += (Random.value - 0.5) * Mathf.Lerp(shootAngleRandomizationAiming, shootAngleRandomizationNotAiming, racioHipHold);
  targetYRotation += (Random.value - 0.5) * Mathf.Lerp(shootAngleRandomizationAiming, shootAngleRandomizationNotAiming, racioHipHold);
  currentRecoilZPos -= recoilAmount;
 

     waitTilNextFire = 1; 
       } 
    }
  waitTilNextFire -= Time.deltaTime * fireSpeed;
     
     if (holdSound)
         holdSound.transform.parent = transform;
     if (holdMuzzelFlash)
         holdMuzzelFlash.transform.parent = transform;
     
     currentRecoilZPos = Mathf.SmoothDamp( currentRecoilZPos, 0, currentRecoilZPosV, recoilRecoverTime);
     
     cameraObject.GetComponent(MouseLookScript).currentTargetCameraAngle = zoomAngle;
     
     if (Input.GetButton("Fire2")){
         cameraObject.GetComponent(MouseLookScript).currentAimRacio = aimRacio;
         racioHipHold = Mathf.SmoothDamp(racioHipHold, 0, racioHipHoldV, hipToAimSpeed);}
     if (Input.GetButton("Fire2") == false){
         cameraObject.GetComponent(MouseLookScript).currentAimRacio = 1;
         racioHipHold = Mathf.SmoothDamp(racioHipHold, 1, racioHipHoldV, hipToAimSpeed);}
     
     transform.position = cameraObject.transform.position + (Quaternion.Euler(0,targetYRotation,0) * Vector3(holdSide * racioHipHold, holdHeight * racioHipHold, 0) + Quaternion.Euler(targetXRotation, targetYRotation, 0) * Vector3(0,0,currentRecoilZPos));
     
     targetXRotation = Mathf.SmoothDamp( targetXRotation, cameraObject.GetComponent(MouseLookScript).xRotation, targetXRotationV, rotateSpeed);
     targetYRotation = Mathf.SmoothDamp( targetYRotation, cameraObject.GetComponent(MouseLookScript).yRotation, targetYRotationV, rotateSpeed);
     
     transform.rotation = Quaternion.Euler(targetXRotation, targetYRotation, 0);
     }
     
     //cameraObject.GetComponent(MouseLookScript).currentTargetCameraAngle = zoomAngle;

Is there any way i can change the speed of bullet? This script has been taken from FPS project,(dont remember name) and i want to change the speed of my bullet. Bullet is prefab and Instantiates as clone when mouse button 0 is pressed. The speed needs to be changed because now its unlimited, literally. I cant hit the object with that speed, it flies through. And heres the Collision script:

 function OnTriggerEnter(other : Collider) {
 
 if(other.CompareTag("Enemy"))
 
     print("Enemy is hit!");
 
     Destroy(other.gameObject);  
 }

It doesnt detect the collision. Please tell me how it can detect the bullet collision and destroy the collided object. This second script is attached to my bullet prefab.

Thanks.

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 Lo0NuhtiK · Jan 25, 2012 at 09:20 PM 1
Share

Why not just use Raycast for Shooting since you're using fast bullets and not something slower and larger like a rocket ??

avatar image syclamoth · Jan 25, 2012 at 11:21 PM 0
Share

If you expect the bullet to take less than 1/60th of a second to reach its target, there's no functional difference between a bullet and a laser.

0 Replies

· Add your reply
  • Sort: 

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

A node in a childnode? 1 Answer

Please tell me what is wrong with this Projectile.js file 1 Answer

Question about fliping a character 1 Answer

Whow do i change my character height 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