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 assassinKK · Mar 04, 2018 at 10:16 PM · movementnetworkinginterpolation

Network transform movement wont interpolate. How do i fix this?

I keep all the default settings in my network transform component but only rotational interpolation takes place over the network. The rotation alone is smooth but the movement only snaps to the Snap Threshold I set to 5 (default). Tweaking other movement values don't seems to make a difference.

Here is my script:

using UnityEngine; using UnityStandardAssets.CrossPlatformInput;

public class TankMovement : MonoBehaviour { public Transform cameraRig;

 public float turnSmoothing = 15f;    
 public float speedDampTime = 0.1f;

 public int m_PlayerNumber = 1;         
 public float m_Speed = 10f;            
 public float m_TurnSpeed = 180f;       
 public AudioSource m_MovementAudio;    
 public AudioClip m_EngineIdling;       
 public AudioClip m_EngineDriving;      
 public float m_PitchRange = 0.2f;

 
 private string m_MovementAxisName;     
 private string m_TurnAxisName;         
 private Rigidbody m_Rigidbody;         
 private float m_MovementInputValue;    
 private float m_TurnInputValue;        
 private float m_OriginalPitch;         


 private void Awake()
 {
     m_Rigidbody = GetComponent<Rigidbody>();
 }


 private void OnEnable ()
 {
     m_Rigidbody.isKinematic = false;
     m_MovementInputValue = 0f;
     m_TurnInputValue = 0f;
 }


 private void OnDisable ()
 {
     m_Rigidbody.isKinematic = true;
 }


 private void Start()
 {
     m_MovementAxisName = "Vertical";
     m_TurnAxisName = "Horizontal";

     m_OriginalPitch = m_MovementAudio.pitch;
 }
 

 private void Update()
 {
     // Store the player's input and make sure the audio for the engine is playing.


     EngineAudio ();
 }


 private void EngineAudio()
 {
     // Play the correct audio clip based on whether or not the tank is moving and what audio is currently playing.
     if(Mathf.Abs(m_MovementInputValue) < 0.1f && Mathf.Abs(m_TurnInputValue) < 0.1f)
     {
         if (m_MovementAudio.clip == m_EngineDriving)
         {
             m_MovementAudio.clip = m_EngineIdling;
             m_MovementAudio.pitch = Random.Range(m_OriginalPitch - m_PitchRange, m_OriginalPitch + m_PitchRange);
             m_MovementAudio.Play();
         }
     }
     else
     {
         if (m_MovementAudio.clip == m_EngineIdling)
         {
             m_MovementAudio.clip = m_EngineDriving;
             m_MovementAudio.pitch = Random.Range(m_OriginalPitch - m_PitchRange, m_OriginalPitch + m_PitchRange);
             m_MovementAudio.Play();
         }
     }
 }


 private void FixedUpdate()
 {

     float h = CrossPlatformInputManager.GetAxis(m_TurnAxisName);
     float v = CrossPlatformInputManager.GetAxis(m_MovementAxisName);

     MovementManagement (h, v);
 }

 void MovementManagement (float horizontal, float vertical)
 {
     // If there is some axis input...
     if(horizontal != 0f || vertical != 0f)
     {
         Vector3 moveVec = new Vector3(horizontal, 0f, vertical) * m_Speed;
         m_Rigidbody.MovePosition (m_Rigidbody.position + moveVec * Time.fixedDeltaTime);
         Rotating (horizontal, vertical);
     }
 }



 void Rotating (float horizontal, float vertical)
 {
     
     // Create a new vector of the horizontal and vertical inputs.
     Vector3 targetDirection = new Vector3(horizontal, 0f, vertical);

     // Create a rotation based on this new vector assuming that up is the global y axis.
     Quaternion targetRotation = Quaternion.LookRotation(targetDirection, Vector3.up);

     // Create a rotation that is an increment closer to the target rotation from the player's rotation.
     Quaternion newRotation = Quaternion.Lerp(GetComponent<Rigidbody>().rotation, targetRotation, turnSmoothing * Time.deltaTime);

     // Change the players rotation to this new rotation.
     m_Rigidbody.MoveRotation(newRotation);
 }

}

Comment
Add comment · Show 5
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 Chik3r · Mar 04, 2018 at 10:34 PM 1
Share

Show us the network transform in the inspector

avatar image assassinKK Chik3r · Mar 07, 2018 at 01:18 PM 0
Share

Here is the image containing my network transform. Does the network transform not interpolate on Android build? Because I am building and testing on Android.

image.png (484.3 kB)
avatar image Chik3r assassinKK · Mar 07, 2018 at 03:25 PM 0
Share

And are you moving via the rigid body or the transform?(Add Force or Translate)

Show more comments

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

148 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 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

Network Trasnform Interpolation Factor 2 Answers

Network Movement Sync Very jumpy. 0 Answers

How to smoothen out ball movement using Photon 1 Answer

Movement interpolation 1 Answer

Unity networking tutorial? 6 Answers


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