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 /
avatar image
0
Question by any7000 · Jun 04, 2013 at 11:19 PM · movementphysicsnetworkingmultiplayervector

bouncing a puck of a vertical wall through code

Hello everybody! I searched through all the questions related to this, but I seem not to get it correctly. I am really lost now so every help is very much appreciated :) I want to do a airhockey game. There are two players (playing with Kinect through networking) that toss a puck with their hands over a field. I got a nice puck movement when using AddForce but when they play remotely it gets all jittery, so I decided not to rely on the physics and bouncing materials but code the movement instead. For the bouncing of the hands it works fine, but when the puck should bounce of the framing walls each side of the field, nothing works. I wanted to reflect the angle, but the puck is flying off to nirvana although initially no y-movement is applied (puck should only move in x and z). This is the code I have so far (attached to the puck):

 private var camScript2 : GameObject;
 private var speed = Vector3(0,0,3);
 
 function Start () {
     Physics.gravity = Vector3(0, -50, 0);
     //rigidbody.AddForce(0,0,-5, ForceMode.Impulse); //direction patient
     //rigidbody.AddForce(0,0,5, ForceMode.Impulse); //direction healthy
     camScript2 = GameObject.Find("Camera");
 }
 
 function Update () {
     transform.Translate(speed * Time.deltaTime);
 }
 
 
 function OnCollisionEnter(collision : Collision) {
     if(Network.isServer){

     var normalpoint : Vector3 = collision.contacts[0].normal;
     var hitpoint : Vector3 = collision.contacts[0].point;
     
     for (var contact : ContactPoint in collision.contacts) {
             
             if (contact.otherCollider.name == "GraspFeedbackSphere"){
                 camScript2.GetComponent(PointsGUI).playerCol = "A";
                 networkView.RPC("updatePuck1", RPCMode.AllBuffered, normalpoint);
             }
             
             if (contact.otherCollider.name == "GrasphSphere"){
                 camScript2.GetComponent(PointsGUI).playerCol = "B";
                 networkView.RPC("updatePuck2", RPCMode.AllBuffered, normalpoint);
             }

             if (contact.otherCollider.name == "Bound_L"){

                var angle = Vector3.Reflect(transform.position, normalpoint);
                speed = angle;
             }

             if (contact.otherCollider.name == "Bound_R"){
                                   
                var angle2 = Vector3.Reflect(transform.position, normalpoint);
                speed = angle2;
             }
        }
    }
 }
 
 @RPC
 function updatePuck1 (impact: Vector3){    
             //move right
             if (impact.x > 0.2){
                 //rigidbody.AddForce(3,0,5, ForceMode.Impulse);
                 speed = Vector3 (3,0,5);
                 }
                 
                 //move to left
             if (impact.x < -0.2){
                 //rigidbody.AddForce(-3,0,5, ForceMode.Impulse);
                 speed = Vector3 (-3,0,5);
                 
                 }
                 
                 //go straight
             else {
                 //rigidbody.AddForce(0,0,5, ForceMode.Impulse);
                 speed = Vector3 (0,0,5);
   
                 }
 }
 
 
 @RPC
 function updatePuck2 (impact: Vector3){
             //move right
            if (impact.x < -0.2){
                 //rigidbody.AddForce(-3,0,-5, ForceMode.Impulse);
                 speed = Vector3 (-3,0,-5);
                 }
                 
             //move to left
             if (impact.x > 0.2){
                 //rigidbody.AddForce(3,0,-5, ForceMode.Impulse);
                 speed = Vector3 (3,0,-5);    
                 }
             //streight
             else {
                 //rigidbody.AddForce(0,0,-5, ForceMode.Impulse);
                 speed = Vector3 (0,0,-5);
                 }

}

The movement of the puck will be sent through RPC as well later, when I got it right :)

Thanks a lot for every hint or help!!!

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

14 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

Related Questions

Unity networking tutorial? 6 Answers

Rocket Jumping Woes 1 Answer

Smoothing Network Movement with OnSerializeNetworkView 0 Answers

Networked player movement very choppy, rotation works fine - UNET 1 Answer

How do I move my character forward and backward, but rotate with left and right and be followed by the camera? 0 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