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
1
Question by Fencer300 · Jun 01, 2013 at 07:23 PM · collisiondropfall

Collision go through help?

I have my main player and I want him so that when he touches a certain object, he appears at another one. I tried using this script to no avail:

 using UnityEngine;
 using System.Collections;

 public class Fun : MonoBehaviour {
 float speed = 5.0f;
 public Transform target;
  
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
     
     }

 void OnCollisionEnter(Collision col) { 
     if (col.gameObject.tag == "Player"){ 
             transform.LookAt(target);
  
         transform.position += transform.forward * speed * Time.deltaTime;
      }
 }
 }

Help will be appreciated!

Comment
Add comment · Show 1
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 Memige · Jun 07, 2013 at 08:05 PM 0
Share

Hey Fencer300, any progress on this? If any of the answers helped you, would you $$anonymous$$d marking them as answered, so that others will be able to get help if they run into the same problem. If you're still fighting this, could you give us an update, so we can try to help you? Thanks.

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Memige · Jun 01, 2013 at 07:59 PM

The Script you have there should (assuming proper setup) cause your trigger object to face the target location and move toward it for one frame. If you want to teleport your Player to the other location, instead of adding a small forward vector to the trigger object, just directly set the Player's position to the target's. Like so:

 col.transform.position = target.position;
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
avatar image
0

Answer by aldonaletto · Jun 01, 2013 at 08:01 PM

Well, this code doesn't seem to do anything remotely similar to what you want - at most the object will move a few milimeters in direction to target when the player touches it.

From your text, it seems that you actually want to teleport the player when it touches this object - is this right? If so, you should make this object a trigger and use OnTriggerEnter: when the player touches the trigger, the code instantly moves him to the target object's position, copying the target rotation as well:

 using UnityEngine;
 using System.Collections;
  
 public class Fun : MonoBehaviour {
   public Transform target; // drag the destination empty object here
  
   void OnTriggerEnter(Collider other) { 
     if (other.tag == "Player"){ // if the player touched the trigger...
        other.transform.position = target.position; // move it to the target position...
        other.transform.rotation = target.rotation; // and assume the target rotation too
     }
   }
 }
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
avatar image
0

Answer by Cowboykilla · Jun 01, 2013 at 09:11 PM

Memige is exactly right with the teleportation script. As for moving... I was thinking maybe just have a static boolean variable called "moving" or something like that preset to false. Then on the Update call, apply the movement portion within an if statement. Also, within that statement have a nested if stating that if the player's location is as close to the target as you'd like, turn off the moving. Something like:

 if (moving==true)
 {
 //Move Script Goes Here
 if (Distance between Player and Target <= 3) // If the player is within a 3 unit radius
 {
 moving=false;
 }
 }

Hope this helps.

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

Character falling but stopped by rigidbody obstacle? 0 Answers

Making a cube fall without rigidbody 1 Answer

the ball falls in a straight line sloping 0 Answers

moving platforms 1 Answer

Nav Mesh Agent won't fall off the platform? 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