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 Sep 29, 2013 at 09:23 AM by Fattie for the following reason:

Duplicate Question

avatar image
-1
Question by Sphyx · Sep 29, 2013 at 01:48 AM · c#conversion

JS to C#, anyone?

Im having trouble converting the following code... Any help is very appreciatted!

 #pragma strict
 var colliding : Collider;
 
 var body : Rigidbody;
 
 var forceMultiplier = 25;
 
 function OnCollisionEnter (collisionInfo : Collision) {
 
     if (collisionInfo.gameObject.name == "Ball") {
 
         var contactNormal = collisionInfo.contacts[0];
 
                 var rot = Quaternion.FromToRotation(Vector3.up, contactNormal.normal);
 
                 var pos = contactNormal.point;
 
                 var rv = collisionInfo.relativeVelocity.magnitude;
 
         direction = body.transform.position - pos;
 
         reflectBallTo = Vector3.Reflect (pos, direction);
 
         colliding.gameObject.rigidbody.AddForce (reflectBallTo * forceMultiplier);
 
     }   
 
 }
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

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by tw1st3d · Sep 29, 2013 at 03:48 AM

Thiiiis should work, might have a few minor bugs. But honestly, I only did this because I had nothing better to do. If it doesn't work, spend time fixing it to work before going any further with C#. That's how you learn, fix stuff up.

 using UnityEngine;
 using System.Collections;
 using System;
 
 public class BallCollide : MonoBehavior
 {
     public Collider colliding;
     public RigidBody body;
     public float forceMultiplier = 25;
      
     public void OnCollisionEnter(Collision collisionInfo) 
     {
         if (collisionInfo.gameObject.name == "Ball")
         {
             string contactNormal = collisionInfo.contacts[0];
             Quaternion rot = Quaternion.FromToRotation(Vector3.up, contactNormal.normal);
             // This might supposed to be something else, but I'm guessing it's a Quaternion.
             float pos = contactNormal.point;
             var rv = collisionInfo.relativeVelocity.magnitude;
             // I have no idea what this is supposed to be, which I'm kicking myself for.
             var direction = body.transform.position - pos;
              // Again, no idea. Might be a float[]
              
             Vector3 reflectBallTo = Vector3.Reflect (pos, direction);
              
             colliding.gameObject.rigidbody.AddForce (reflectBallTo * forceMultiplier);
         }
     }
 }
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 Sphyx · Sep 29, 2013 at 03:55 AM 0
Share

I mannaged to do something next to it... thanks for the help!

Follow this Question

Answers Answers and Comments

17 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

Related Questions

Need help converting js to C 1 Answer

Need help converting js to C# - rigidbody.rotation.z 1 Answer

Need help C# -- yield, destroy 1 Answer

Multiple Cars not working 1 Answer

Need help converting js to C 2 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