- Home /
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.
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.
Your answer
Follow this Question
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