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 Jonathan Genesis · Dec 27, 2013 at 07:53 PM · collisioncollidervector2

Non - Physics collision System

OK, so I have a cube using the new physics 2D toolset in Unity 4.3 and I control it using vector2 and transform and I have it line cast to detect if their is an object to the sides, front, and back. That works but when it detects an object on the solid layer I can't figure out how to make the player stop moving. Here is my script. alt text #pragma strict

 var speed : float;    //speed of the player
 var PosH : float;    //value of change in the Horizontal axis of the controller    
 var PosV : float;    //value of change in the Vertical axis of the controller
 var bullet : Rigidbody2D;    //Projectile being shot has a Rigidbody2D component
 var GunPoint : Transform;    //Point at the tip of the gun where the bullet is instantiated
 var bulletspeed : float;    //Constant speed the bullet goes
 var facing: Vector3 = new Vector3(0.0f, 1.0f, 0.0f); //default to facing "up"
 var deadzone: float = 0.1;
 //
 var Right : boolean = false;
 var Left : boolean = false;
 var Up : boolean = false;
 var Down : boolean = false;
 //
 var RightT : Transform;
 var LeftT : Transform;
 var UpT : Transform;
 var DownT : Transform;
 //
 
 function FixedUpdate(){
 if ( Mathf.Abs(PosH) > deadzone || Mathf.Abs(PosV) > deadzone) {
     facing = new Vector3(PosH, PosV, 0.0f);
     facing.Normalize();
 }
 //
 Right = Physics2D.Linecast(transform.position, RightT.position, 1 << LayerMask.NameToLayer("Solid"));
 Left = Physics2D.Linecast(transform.position, LeftT.position, 1 << LayerMask.NameToLayer("Solid"));
 Up = Physics2D.Linecast(transform.position, UpT.position, 1 << LayerMask.NameToLayer("Solid"));
 Down = Physics2D.Linecast(transform.position, DownT.position, 1 << LayerMask.NameToLayer("Solid"));
 //
 PosH = (Input.GetAxis("Horizontal"));
 PosV = (Input.GetAxis("Vertical"));    
 
 gameObject.transform.position.x = gameObject.transform.position.x + speed * PosH;
 gameObject.transform.position.y = gameObject.transform.position.y + speed * PosV;
 gameObject.transform.LookAt(transform.position + Vector3(PosH, PosV, 0.0), Vector3.forward);
 gameObject.transform.rotation.y = 0;
 gameObject.transform.rotation.x = 0;
 
 if(Input.GetAxis("TriggerRight") > 0){ 
     Shoot();
     }
 }
 
 function Shoot(){
     var bulletInstance = Instantiate(bullet, GunPoint.position, Quaternion.Euler(facing));
     bulletInstance.velocity = facing * bulletspeed;
     Destroy (bulletInstance.gameObject, 1);
 }        


screen shot 2013-12-27 at 1.46.26 pm.png (368.4 kB)
Comment
Add comment · Show 3
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 Jonathan Genesis · Dec 28, 2013 at 07:52 PM 0
Share

Can someone please help me out on this I really need to get this done Im on a time limit in the mean time I'm still trying everything to get this to work right.

avatar image Jonathan Genesis · Dec 28, 2013 at 09:06 PM 0
Share

If anyone has a way to get 2 2DBoxColliders NOT 2DRIGIDBODIES to collide with each other and not intersect that would also be great and would solve my problem.

avatar image Benproductions1 · Dec 29, 2013 at 02:51 AM 0
Share

Please do not bump questions that are at least a month or so old. There are questions from 2009 that still haven't been answered, so get in line and please be patient :)

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

19 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How to make an arrow to become stuck? 1 Answer

Cover mechanic - Restrict movement to box 1 Answer

Keep particles to defined area, destroy on collision 0 Answers

How to check if an object has collided with a specified object from a script 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