Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Thomas-Hawk · Jan 15, 2017 at 06:41 AM · rotationnetworkingtransformservernetworkplayer

Lookat function working before implementing Multiplayer / Networking.

My player object and script are working and flying around with networking just fine. My bullets are instantiating, moving forward which their own script tells them to, but not doing their "LookAt Target" thing on their start frame.

I even defined the instantiate inside a variable and am using NetworkServer.Spawn as the unity basic multiplayer setup manual says.

What am I missing?

Here is the code. Update is running, Start does not seem to be.

 using UnityEngine;
 using System.Collections;
 using UnityEngine.Networking;
 public class shotmover : NetworkBehaviour {
     public float speed;
     public bool hasTarget;
     public Transform target;
     public Player player;
     public Transform initpos;
     public Vector3 targetahead;
 //    public AudioSource pew;
 
     public float smoothTime = 0.3F;
     private Vector3 velocity = Vector3.zero;
     public float offsetz;
     public float offsety;
     public float offsetx;
     public float VertOffset;
     public float FollowHeight;
     public float FollowDistance;
     public float showme;
     public float showme2;
     public Rigidbody rb;
     bool flip;
     // Use this for initialization
     void Start() {
 
 
         //RpcLockon ();
     }
     
     // Update is called once per frame
     void FixedUpdate () {
 
     //    if (!hasTarget)
         gameObject.transform.Translate (Vector3.forward * speed);
         //rb.AddForce(transform.forward * speed);
         if (hasTarget) {
             Debug.DrawLine (gameObject.transform.position, targetahead);
             Debug.DrawLine (target.transform.position, targetahead);
             Debug.DrawLine (initpos.transform.position, targetahead);
         }
     //    if (hasTarget) {
     //        Vector3 targetPosition = target.TransformPoint (new Vector3 (VertOffset, FollowHeight, FollowDistance));
     //        transform.position = Vector3.SmoothDamp (transform.position, targetPosition, ref velocity, smoothTime);
     //        transform.rotation *= Quaternion.Euler (offsetz, offsety, offsetx);
     //    }
     }
 
 
     public void Destroyshot(){
         Destroy (gameObject, 2f);
     }
     [ClientRpc]
     void RpcLockon(){
         rb = gameObject.GetComponent<Rigidbody> ();
 
 
         Destroyshot ();
         hasTarget = player.seesTarget;
 
         if (hasTarget) {
 
             target = player.locktarget;
             initpos = target.transform;
             showme2 = (Vector3.Distance (transform.position, target.position));
             //if (showme > showme2)
             //targetahead += target.position + target.forward * (((Vector3.Distance(transform.position, target.position)) / 100) * (player.locktarget.gameObject.GetComponent<Rigidbody> ().velocity.magnitude));
             targetahead += target.position +  (target.GetComponent<Rigidbody>().velocity) + player.locktarget.gameObject.GetComponent<Rigidbody> ().velocity/showme2*(Mathf.Sqrt((Mathf.Sqrt(showme2)/speed) * (Mathf.Pow(Mathf.Sqrt(player.locktarget.gameObject.GetComponent<Rigidbody> ().velocity.magnitude), rb.velocity.magnitude)+Mathf.Pow(showme2, Mathf.Sqrt(showme))-Mathf.Sqrt(showme)+player.locktarget.GetComponent<Rigidbody>().velocity.sqrMagnitude-speed)));
             //targetahead += target.position - player.locktarget.gameObject.GetComponent<Rigidbody> ().velocity * (Mathf.Sqrt((Mathf.Sqrt(showme2)) * (Mathf.Pow(player.locktarget.gameObject.GetComponent<Rigidbody> ().velocity.magnitude, rb.velocity.magnitude)+Mathf.Pow(showme2, Mathf.Sqrt(showme))+Mathf.Sqrt(showme)+Mathf.Sqrt(player.locktarget.GetComponent<Rigidbody>().velocity.sqrMagnitude))));
             transform.LookAt (targetahead);
             Debug.Log ("Target velocity:" + player.locktarget.gameObject.GetComponent<Rigidbody> ().velocity.magnitude.ToString ());
             showme = (Vector3.Distance(targetahead, target.position));
 
             Debug.Log ("Distance:" + showme2.ToString ());
             Debug.Log ("Targeting forward ahead:" + showme.ToString ());
             //rb.AddForce(transform.forward * speed);
 
             //gameObject.transform.Translate (Vector3.forward * speed);
 
         }
     }
 }
 

Everything in RpcLockon was originally in Start but neither way is working

I would also like to include my player script. My player grabs "locktarget" with a trigger collider. Those trigger collisions dont seem to be happening anymore. What's up? using UnityEngine; using System.Collections; using UnityEngine.Networking;

 public class Player : NetworkBehaviour {
     public float shotTime;
     public float shotCooldown;
     CharacterController cc;
     public float speed;
     public float turnspeed;
     public ParticleSystem engineparticle;
     public float boost;
     public float boostHolder;
     public bool isBoosting;
     public Transform shotpos;
     public GameObject shot;
     public Rigidbody rb;
     public Vector3 forward;
     public bool onGround;
     public float vfloat;
 
 
     public float pitch;
     public float yaw;
     public float roll;
 
     public bool seesTarget;
     public Transform locktarget;
 
     public PlayerHealth php;
     NetworkIdentity nid;
     //public float
     //public float
     //public float
 
 
     // Use this for initialization
     void Start () 
     {
         shotTime = shotCooldown;
         nid = GetComponent<NetworkIdentity> ();
         onGround = false;
         forward = Vector3.forward;
         engineparticle.Stop ();
     //    displaceHolder = displaceAmount;
         cc = GetComponent<CharacterController> ();
     //    lengthpos = new Vector3 (transform.position.x, transform.position.y, transform.position.z - displaceAmount);
     }
 
     void Update (){
         shotTime -= .1f;
         if (!isLocalPlayer) {
             return;
         } 
             pitch = -Input.GetAxis ("Vertical");
             yaw = -Input.GetAxis ("Horizontal");
             roll = Input.GetAxis ("Roll");
 
     }
     
     // Update is called once per frame
     void FixedUpdate () {
         if (!isLocalPlayer) {
             return;
         }
 
     //Always move the player forward, relative to its rotation.
         //rb.AddRelativeForce(Vector3.up * (speed + boostHolder));
         //rb.MovePosition(Vector3.forward * (speed + boostHolder));
 
         /*
         transform.Translate(forward * (speed + boostHolder));
         transform.Rotate(vfloat * turnspeed,  Input.GetAxis("Horizontal") * turnspeed, ((Input.GetAxis("Horizontal") / 3) * -1) + Input.GetAxis("Roll") * -turnspeed);
 
 */
         if (!Input.GetKey(KeyCode.Space)) {
             rb.AddRelativeForce (Vector3.up * (speed + boostHolder));
 
         }
         //transform.Rotate(pitch * turnspeed,  roll * turnspeed, ((roll / 3) * -1) + yaw * -turnspeed, relativeTo:Space.Self);
         rb.AddRelativeTorque (pitch * turnspeed, -roll * turnspeed,((roll / 3)+ yaw) * -turnspeed);
 
 
         //rb.AddTorque (Input.GetAxis("Vertical") * turnspeed,  Input.GetAxis("Horizontal") * -turnspeed,0);
         //transform.Rotate(vfloat * turnspeed,  Input.GetAxis("Horizontal") * turnspeed, ((Input.GetAxis("Horizontal") / 3) * -1) + Input.GetAxis("Roll") * -turnspeed);
         //Rotate left and right with a and d, rotate up and down with w and s.
 
 
 
 
     /*    if (Input.GetKey (KeyCode.S) && !onGround)
             vfloat = -1f;
         if (Input.GetKey (KeyCode.W))
             vfloat = 1f;
         else
             vfloat = 0f;*/
         //while you press shift,
         if (Input.GetKey (KeyCode.LeftShift)) {
             isBoosting = true;
             engineparticle.gameObject.SetActive (true);
         } else {
             isBoosting = false;
             engineparticle.gameObject.SetActive (false);
         }
         if (isBoosting)
             boostHolder = boost;
         else
             boostHolder = 0;
 
 
 
         //If the player press space,
         if (Input.GetMouseButton(1) && shotTime <= 0f) {
             CmdFire ();
             shotTime = shotCooldown;
             //NetworkServer.Spawn(Coneshot);
             //Coneshot.GetComponent<shotmover>().Start
         }
 
         //instantiate a shot, at shotpos.
     
     }
 
     void OnTriggerStay(Collider other){
         Debug.Log ("Trigger enter");
         //Collide with a certain thing to trigger an instantiation method.
         //if (other.CompareTag ("terrain")) {
             //forward += new Vector3 (0, 1, 0);
             //onGround = true;
 
         //}
         if (other.CompareTag ("enemy") && !seesTarget) {
             other.GetComponent<FlightAI> ().isTargeted = true;
             other.GetComponent<FlightAI> ().targetind.gameObject.SetActive (true);
             seesTarget = true;
             locktarget = other.gameObject.transform;
             Debug.DrawLine (transform.position, locktarget.position);
             Debug.Log ("See target");
             //Debug.Log ("Target at distance" + Vector3.Distance (transform.position, locktarget.position).ToString ());
         }
     }
 
     void OnTriggerExit(Collider other){
         //if (other.CompareTag ("terrain")) {
             ////anim.SetBool ("hitground", false);
             //forward = Vector3.forward;
             //onGround = false;
             //php.hp -= 10f;
     //    }
         if (other.CompareTag ("enemy")) {
             other.GetComponent<FlightAI> ().isTargeted = false;
             other.GetComponent<FlightAI> ().targetind.gameObject.SetActive (false);
             seesTarget = false;
             locktarget = null;

             Debug.Log ("Lost target");
         }
 
 
 
     }
 
 

 
  
 
 
 }
 
Comment
Add comment · Show 1
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 LK84 · Jan 15, 2017 at 11:08 AM 0
Share

please provide the relevant code

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

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

Related Questions

Unity networking tutorial? 6 Answers

Updating rotation of client not working - strange error 0 Answers

How to reduce lag in Network Transform Componented Player in UNET? 2 Answers

Network Transform Slow Rotations 0 Answers

Make camera 1 transform equal to camera 2 transform 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