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 filika · Dec 08, 2013 at 08:37 PM · collision

Colliders with JS only

I am generating some simple 3d object with JS coding. I am able to add Mesh Collider as well. But I need to find a way to make it convex. Do you know any code samples for that? Thanks in advance

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by meat5000 · Dec 08, 2013 at 08:38 PM

http://docs.unity3d.com/Documentation/ScriptReference/MeshCollider-convex.html

Comment
Add comment · Show 4 · 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 filika · Dec 08, 2013 at 09:22 PM 0
Share

Assets/Element.js(107,61): BCE0019: 'convex' is not a member of 'UnityEngine.Collider'.

avatar image filika · Dec 08, 2013 at 09:22 PM 0
Share

Are you sure that it works for JS?

avatar image meat5000 ♦ · Dec 08, 2013 at 09:24 PM 0
Share

Post your code

Show more comments
avatar image
0

Answer by filika · Dec 09, 2013 at 10:25 AM

I have a public class named Element #pragma strict

public class Element { private var elementContainer: GameObject; private var cubeFront : GameObject; private var cubeFrontUp : GameObject; private var cubeFrontDown : GameObject; private var cubeBack : GameObject; private var cubeLeft : GameObject; private var cubeRight : GameObject; private var cubeBottom : GameObject; private var cubeTop : GameObject; private var cubeHole : GameObject; private var woodThickness : float = 1; private var hole : int; public var xPos : int = 0; public var yPos : int = 0; public var moveMe : int = 1;

     public function Element(bWidth : int, bHeight : int, bDepth : int, nFrontface : int, hole : int) 
     {
     
     
         elementContainer = new GameObject("Element Container");
         //elementContainer.AddComponent(Rigidbody);
         //elementContainer.rigidbody.isKinematic = true;
         elementContainer.AddComponent(MeshCollider);
         //Debug.Log(elementContainer.transform.collider);
         
         
         
         
         if(nFrontface == 1){
 
         //Front
         cubeFront  = GameObject.CreatePrimitive(PrimitiveType.Cube);
         cubeFront.transform.localScale = Vector3(bWidth,bHeight,woodThickness);
         cubeFront.transform.localPosition = Vector3(0,bHeight * 0.5, -1 * bDepth * 0.5 + woodThickness*0.5);
         cubeFront.renderer.material.mainTexture = Resources.Load("H3375_ST22", Texture2D);
         cubeFront.transform.parent = elementContainer.transform;
         
         
         }else if(nFrontface == 2){
         
         
         //FrontUp
         cubeFrontUp  = GameObject.CreatePrimitive(PrimitiveType.Cube);
         cubeFrontUp.transform.localScale = Vector3(bWidth,bHeight*0.5-woodThickness*0.2,woodThickness);
         cubeFrontUp.transform.localPosition = Vector3(0,bHeight * 0.75, -1 * bDepth * 0.5 + woodThickness*0.5);
         cubeFrontUp.renderer.material.mainTexture = Resources.Load("200s", Texture2D);
         cubeFrontUp.transform.parent = elementContainer.transform;
         //FrontDown
         cubeFrontDown  = GameObject.CreatePrimitive(PrimitiveType.Cube);
         cubeFrontDown.transform.localScale = Vector3(bWidth,bHeight*0.5-woodThickness*0.2,woodThickness);
         cubeFrontDown.transform.localPosition = Vector3(0,bHeight * 0.25, -1 * bDepth * 0.5 + woodThickness*0.5);
         cubeFrontDown.renderer.material.mainTexture = Resources.Load("200s", Texture2D);
         cubeFrontDown.transform.parent = elementContainer.transform;
         
         }
         
         //Back
         cubeBack  = GameObject.CreatePrimitive(PrimitiveType.Cube);
         cubeBack.transform.localScale = Vector3(bWidth,bHeight,woodThickness);
         cubeBack.transform.localPosition = Vector3(0,bHeight * 0.5, bDepth * 0.5 - woodThickness*0.5);
         cubeBack.renderer.material.mainTexture = Resources.Load("H3375_ST22", Texture2D);
         cubeBack.transform.parent = elementContainer.transform;
         
         //Left
         cubeLeft  = GameObject.CreatePrimitive(PrimitiveType.Cube);
         cubeLeft.transform.localScale = Vector3(woodThickness,bHeight,bDepth);
         cubeLeft.transform.localPosition = Vector3(-1 * bWidth * 0.5 + woodThickness*0.5,bHeight * 0.5, 0);
         cubeLeft.renderer.material.mainTexture = Resources.Load("H3375_ST22", Texture2D);
         cubeLeft.transform.parent = elementContainer.transform;
         
         //Right
         cubeRight  = GameObject.CreatePrimitive(PrimitiveType.Cube);
         cubeRight.transform.localScale = Vector3(woodThickness,bHeight,bDepth);
         cubeRight.transform.localPosition = Vector3(bWidth * 0.5 - woodThickness*0.5,bHeight * 0.5, 0);
         cubeRight.renderer.material.mainTexture = Resources.Load("H3375_ST22", Texture2D);
         cubeRight.transform.parent = elementContainer.transform;
         
         //Bottom
         cubeBottom  = GameObject.CreatePrimitive(PrimitiveType.Cube);
         cubeBottom.transform.localScale = Vector3(bWidth,woodThickness,bDepth);
         cubeBottom.transform.localPosition = Vector3(0,woodThickness*0.5, 0);
         cubeBottom.renderer.material.mainTexture = Resources.Load("H3375_ST22", Texture2D);
         cubeBottom.transform.parent = elementContainer.transform;
         
         //Top
         cubeTop  = GameObject.CreatePrimitive(PrimitiveType.Cube);
         cubeTop.transform.localScale = Vector3(bWidth,woodThickness,bDepth);
         cubeTop.transform.localPosition = Vector3(0,bHeight, 0);
         cubeTop.renderer.material.mainTexture = Resources.Load("200s", Texture2D);
         //cubeTop.renderer.material.color = Color.gray;
         cubeTop.transform.parent = elementContainer.transform;
         
         
         if(hole == 1){
         //Hole
         cubeHole  = GameObject.CreatePrimitive(PrimitiveType.Cube);
         cubeHole.transform.localScale = Vector3(10,0,3);
         cubeHole.transform.localPosition = Vector3(0,bHeight+1, bDepth*0.5-1.8);
         cubeHole.renderer.material.color = Color.gray;
         cubeHole.transform.parent = elementContainer.transform;
         
         }
         
         
         
     }
     
     function Place (_xPos : int, _yPos : int)
     {
                 xPos = _xPos;
                 yPos = _yPos;
                 elementContainer.transform.localPosition = Vector3(xPos,yPos, 0);
                 
     
     }
     
     function Start ()
     {
     
     }
 
     function Update ()
     {
     
     
         
     }
     
     
 
 

}

I want to access the variable named moveMe from a Main JS code #pragma strict

private var wall : GameObject; private var floor : GameObject;

private var mouseScreen : Vector3 = new Vector3(0,0,0); private var mouseWorld : Vector3 = new Vector3(0,0,0); private var offSet : Vector3 = new Vector3(0,0,0);

private var woodThickness : float = 1;

function Start () {

 //camera positioning
 this.transform.position = Vector3(90,150,-250);
 this.transform.Rotate(15,-5,0);
 
 // Make a game object
 
 var lightGameObject : GameObject = new GameObject("The Light");
 
 // Add the light component
 lightGameObject.AddComponent(Light);
 // Set color and position
 lightGameObject.light.color = Color.white;
 lightGameObject.light.type = LightType.Directional;
 lightGameObject.light.intensity = 0.4;
 // Set the position (or any transform property) after
 // adding the light component.
 lightGameObject.transform.position = Vector3(0, 500, 0);
 lightGameObject.transform.Rotate(40, 5, 200);
 
 //point light
 var pointLightGameObject : GameObject = new GameObject("The Point One");
 
 // Add the light component
 pointLightGameObject.AddComponent(Light);
 // Set color and position
 pointLightGameObject.light.color = Color.white;
 pointLightGameObject.light.type = LightType.Point;
 pointLightGameObject.light.intensity = 1;
 pointLightGameObject.light.range = 130;
 // Set the position (or any transform property) after
 // adding the light component.
 pointLightGameObject.transform.position = Vector3(60, 140, -31);
 pointLightGameObject.transform.Rotate(40, 5, 200);
 
 
 //create Background Wall and Floor
 wall = GameObject.CreatePrimitive(PrimitiveType.Cube);
 wall.transform.position = Vector3(0,150,30);
 wall.transform.localScale = Vector3(800,2,300);
 wall.transform.Rotate(90,0,0);
 wall.renderer.material.mainTexture = Resources.Load("wall", Texture2D);
 wall.renderer.material.mainTextureScale = Vector2 (11,11);
 
 //floor
 floor = GameObject.CreatePrimitive(PrimitiveType.Cube);
 floor.transform.position = Vector3(0,0,-120);
 floor.transform.localScale = Vector3(800,2,300);
 floor.transform.Rotate(0,0,0);
 floor.renderer.material.mainTexture = Resources.Load("wooden-floor-texture", Texture2D);
 floor.renderer.material.mainTextureScale = Vector2 (11,11);


 //create Elements
 var myStuff : Element = new Element(130,40,50,2,1);
 myStuff.Place(97,8);
  
 var myStuff2 : Element = new Element(65,40,50,1,0);
 myStuff2.Place(0,8);
  
 var myBase : Base = new Base(195,8,46);
 myBase.Place(65,0);
 

}

function Update () { var mainCamera = Camera.main; var hit : RaycastHit; //Debug.Log(Input.mousePosition); //Debug.Log(mainCamera.ScreenPointToRay(Input.mousePosition));

 if (Input.GetMouseButtonDown (0)){
 
     if( Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition),  hit ) ) {
         
         mouseScreen = Vector3(Input.mousePosition.x,Input.mousePosition.y,-1 * mainCamera.transform.position.z);
         
         mouseWorld = mainCamera.ScreenToWorldPoint(mouseScreen);
         
         offSet = mouseWorld-hit.transform.position;        
     
         
     }
         
 
 }
 
 if (Input.GetMouseButton (0)){
 
     if( Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition),  hit ) ) {
         
         mouseScreen = Vector3(Input.mousePosition.x,Input.mousePosition.y,-1 * mainCamera.transform.position.z);
         
         mouseWorld = mainCamera.ScreenToWorldPoint(mouseScreen);
         
         
         // here I'd like to get the variable moveMe
         
         if(hit.rigidbody){
         
         
         hit.transform.position.x = mouseWorld.x - offSet.x;
         hit.transform.position.y = mouseWorld.y - offSet.y;
         hit.transform.position.z = 0;            
         }
    
     }
 }
 
  

} thanks a lot for your help

Comment
Add comment · 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

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

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

A node in a childnode? 1 Answer

support not detected collision and Leasehold 0 Answers

How to add to a 3D object's length through code? 1 Answer

Make invisible wall appear visible upon collision/detection 1 Answer

reset level on collision 3 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