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 TheRichardGamer · Nov 19, 2013 at 04:24 PM · transformpositionvector3physic

What is wrong with my zipline script?

Hi, I am making a zipline thing, and I'm almost done, but there's one error that I get when I walk over a trigger, it says "NullReferenceException: Object reference not set to an instance of an object Zipline.OnTriggerEnter (UnityEngine.Collider Other) (at Assets/Zipline.js:15)" What is wrong here?

Here's my script:

 var EndPoint : Transform;
 
 public var IsRiding = false;
 
 var PlayerPhysic : CharacterMotor;
 
 var Player : GameObject;
 
 var Speed : float;
 
 function OnTriggerEnter(Other : Collider){
     
     if(Other.gameObject.tag == "Player"){
     
     Player.position = Vector3.MoveTowards(Player.position, EndPoint.position, Speed * Time.detlaTime);    
         IsRiding = true;
         
         }
     
    }
    
    
    function Update () {
        
        if(IsRiding == true){
            
        PlayerPhysic.enabled = false;    
            
            
        }
        
   
        
             if(IsRiding == false){
            
        PlayerPhysic.enabled = true;    
            
            
        }
        
        
        
    }
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
1

Answer by ArkaneX · Nov 19, 2013 at 04:34 PM

It looks like your Player or EndPoint variable is not assigned, so it is null. Trying to access any member of such null variable results in NullReferenceException...

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 TheRichardGamer · Nov 19, 2013 at 07:33 PM 0
Share

No, you see, I have assigned them properly, I think there is something else that is wrong. It mentions line #15 when I get the error, so I'm guessing I have done something wrong with my script.

avatar image ArkaneX · Nov 19, 2013 at 07:43 PM 0
Share

Please add this just before line 15, i.e. Player.position = Vector3.$$anonymous$$oveTowards(...)

 print(Player);
 print(EndPoint);

and see what is printed to the console.

avatar image TheRichardGamer · Nov 19, 2013 at 08:13 PM 0
Share

It prints

Player (UnityEngine.Transform) UnityEngine.$$anonymous$$onoBehaviour:print(Object)

EndPoint (UnityEngine.Transform) UnityEngine.$$anonymous$$onoBehaviour:print(Object)

But I've managed to make it move, but the thing is that it moves in just one millisecond, it doesn't have a smooth effect between the positions:

    function OnTriggerEnter(Other : Collider){
     
     if(Other.gameObject.tag == "Player"){
     
          print(Player);
        print(EndPoint);
     
     Player.transform.position = Vector3.Lerp(Player.transform.position, EndPoint.transform.position, 3 * Time.deltaTime);
         IsRiding = true;
         
         }
     
    }
    
avatar image ArkaneX · Nov 19, 2013 at 08:37 PM 0
Share

If it prints correct values, then you probably made some fix ;)

Regarding movement - you can use lerping in coroutine to achieve smooth effect. For example please see this answer.

avatar image
0

Answer by ValrikRobot · Mar 12, 2015 at 01:09 PM

You could always try this, very easy to use http://u3d.as/content/valrik/zip-n-swing

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

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

Vector3 Transform.Position Not Working 2 Answers

Why does this placement script not work? 1 Answer

Vector movement according to rotation glitching out at non-square angles. 0 Answers

Player not facing the mouse correctly 1 Answer

Script to make Camera follow the player C# 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