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 /
This question was closed May 07, 2018 at 08:15 AM by Myth for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Myth · Jul 19, 2010 at 02:49 AM · rotatesynchronizationturretfireguns

Turret control Problem

Ok, here we go.

I am trying to create a turret system in which you have control of a set of turrets at the same time. The turrets will turn in unison with same rotation and gun elevation.

These turrets could be considered to be equivalent to AA batteries on a battleship but with only one operator.

The turrets aren't meant to be AI controlled, they are meant to be player controlled and rotate in synchronization. The objective is not accuracy, but for the player to be able to spray fire in a general direction.

The guns will also fire at the same time.

(if you don't understand, check out any ship in battlefield1942)

I think the hierarchy should be

0 star cruiser 1 game object

2 all add on turrets + control turret

3 camera (sub to control turret)

Not sure on the scripting but have tried to use mouselook and failed

I have been attempting to create my own .js from scratch but cannot stop the first turret (haven't even tried to link them yet) from rotating around the z axis.

I am aware that I need to tell it to rotate in global, not local, space but as of yet I have had no luck.

My plan was to have a control script on the turret with the camera, a variables script on the parent and a follow script on all the other turrets that obtains the rotation and fire commands from the parent.

You can probably do it without the variables script but once again, I'm not sure how.

Any help would be greatly appreciated!!

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

4 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by Myth · Jan 30, 2011 at 02:19 PM

solution

use the same controlling script for all turrets - the input is the same so the angles will be the same provided they all have the same rotation to start with (also no fancy business with sending messages)

attach the camera to one

and it works

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
avatar image
2

Answer by kilgore · Jul 19, 2010 at 03:42 AM

There are definitely a million different ways you could control multiple turrets in sync. The following is a C# example that might point you in the right direction. This would be attached to the player's ship. Each turret would have a "Turrets" tag assigned to it and would be a child of the ship.

using UnityEngine; using System.Collections;

public class TurretControl : MonoBehaviour { public int rotMult = 30;

private GameObject[] turrets; private float xRot = 0; private float yRot = 0;

void Start() { turrets = GameObject.FindGameObjectsWithTag("Turrets"); } void Update() { xRot += Input.GetAxis("Vertical") rotMult Time.deltaTime; yRot += Input.GetAxis("Horizontal") rotMult Time.deltaTime;

 for (int i = 0; i < turrets.Length; i++)
     turrets[i].transform.rotation = Quaternion.Euler(new Vector3(xRot, yRot, 0));

} }

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 Myth · Jul 19, 2010 at 11:42 AM 0
Share

Thanks for trying but...

This script controls all objects tagged turret. I need one that only controls one battery of say five turrets

also it $$anonymous$$UST be mouse controlled.

Sorry I didn't mention it above.

avatar image
1

Answer by Julian-Glenn · Jul 19, 2010 at 03:03 AM

Not sure from you post exactly what is or isn't working, but this should get you started on rotating the Turrets

And maybe you could use BroadcastMessage to tell the other turrets how to rotate.

Also look at the FPS tutorial as it has some turrets that follow the player and attack. Lots of good code to start from in that Tutorial

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 Myth · Jul 19, 2010 at 11:28 AM 0
Share

Firstly, thanks for your post.

not sure how to implement the broadcast message as I literally just switched from Dark Basic (completely code based and majorly simplified!) to Unity.

avatar image
0

Answer by Myth · Jul 19, 2010 at 11:53 AM

/CODE

// control vars

var speed : int = 3; var friction : float = 1.0; var lerpSpeed : float = 1.5;

//angles private var xDeg : float = 0.0; private var yDeg : float = 0.0;

//no idea but it works - part of calc we didn't cover at westland high private var fromRotation : Quaternion; private var toRotation : Quaternion;

//shooting var bulletPrefab : Transform;

function Update () { xDeg -= Input.GetAxis("Mouse X") speed friction; yDeg += Input.GetAxis("Mouse Y") speed friction; fromRotation = transform.rotation; toRotation = Quaternion.Euler(yDeg,xDeg,0); transform.rotation = Quaternion.Lerp(fromRotation,toRotation,Time.deltaTime * lerpSpeed);

if (Input.GetButtonDown("Fire1"))
{
    var bullit = Instantiate(bulletPrefab,transform.Find("Spawn Point").transform.position, Quaternion.identity);
    bullit.rigidbody.AddForce(transform.forward * 2000);
}

}

*/CODE

Here is what I meant to post ( copied the wrong code before)

Still cannot get the z axis to stay at a fixed rotation of ZERO.

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

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

My bullets wont slow down 1 Answer

Mini Gun Turret 1 Answer

Rotating object towards mouse point 1 Answer

Turrets acting oddly when clamped 1 Answer

transform.LookAt causes my object to explode 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