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
1
Question by alireza97 · Sep 15, 2019 at 02:58 PM · transform.positiontransform.rotation

How to Move and Rotate Ball at the same time by code

Hi.

I'm creating a multiplayer Football Game like Soccer Stars.

when 'a' shot, I send the ball position every 200 milliseconds and the other player get it and try to replay movements of ball and units. here is a sample code for this:

Movent Class:

 public class Movements
 {
     public float time;
     public Vector3 position;
     public Movement_From_Server(Vector3 pos, float t)
     {
         time = t;
         position = pos;
     }
 }

and GameObjects function:

 List<Movements> Positions = new List<Movements>();
 int index = 0;
 void Replay_Movements()
 {
     if (index < Positions.Count)
     {
         movement_timer += Time.deltaTime;
         float _deltaT = Positions[index].time - Positions[index - 1].time;
         if (_deltaT > 0)
         {
             float _deltaX = (Positions[index].position.x - Positions[index - 1].position.x) / _deltaT;
             float _deltaZ = (Positions[index].position.z - Positions[index - 1].position.z) / _deltaT;
 
             transform.position = new Vector3(Positions[index - 1].position.x + (_deltaX * movement_timer), Positions[index - 1].position.y, Positions[index - 1].position.z + (_deltaZ * movement_timer));
         }
         if (movement_timer >= _deltaT)
         {
             movement_timer = 0;
             transform.position = Positions[index].position;
             index++;
         }
     }
     
 }

this works for units but when I add it for the ball doesn't work.

I think it might be because of that my unit's rotation of x and z is freeze but the ball rotation has no freeze.

(and I don't know how exactly replay rotate the ball to make it the same as the other player) any idea?

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

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

114 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

Related Questions

The instantiated prefab doesn't fire correctly from the player 2 Answers

How to align & rotate objects to each other at run time? 1 Answer

any way to access the global position and rotation of a child object? 1 Answer

Vertical Camera Orbit 0 Answers

How to get updated Transform of a spawned object? 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