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 RuneyWolf · Sep 16, 2013 at 03:45 AM · errorrigidbodyprefab

CS0176: An error I can't move past with rigidbody raycasting

So I've just begun work with raycasting and was ecstatic when I finally got my first Raycast up and running. However in modifying it I have hit a snag. Unity keeps popping this wonderful phrase up and google has yielded no results that were helpful. Here is the error:

Assets/PlayerAttack.cs(18,95): error CS0176: Static member `UnityEngine.Vector3.forward' cannot be accessed with an instance reference, qualify it with a type name instead

Here is my code:

 using UnityEngine;
 using System.Collections;
 
 public class PlayerAttack : MonoBehaviour {
 
 
     // Use this for initialization
     void Start () {
     }
     
     // Update is called once per frame
     void Update () {
         RaycastHit hit;
           Vector3 fwd = transform.TransformDirection(Vector3.forward);
         if(Input.GetKeyDown(KeyCode.E)){
             if(Physics.Raycast(Camera.main.transform.position, fwd, out hit, 10)){
                 if(hit.collider.tag == "Palmtree"){
                     hit.rigidbody.AddForce(Camera.main.transform.position.forward);
                 }
             }
         }
     }
 }

Anyone have any idea?

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 getyour411 · Sep 16, 2013 at 04:00 AM 0
Share

I guess there is no Camera.main.transform.position.forward; this looks a bit odd can you confirm what you want to happen when the player presses E and the raycast hits the palmtree - what do you want to move?

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by vexe · Sep 16, 2013 at 03:50 AM

The forward vector inside the Vector3 class is static, you access it like Vector3.forward, like you did correctly.

But then you wrote:

 hit.rigidbody.AddForce(Camera.main.transform.position.forward);

position is Vector3 instance, right? and you're trying to access the static member forward from it, that's why it's barking that error.

Use either Vector3.forward, unless you meant Camera.main.transform.forward

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 RuneyWolf · Sep 16, 2013 at 04:05 AM 0
Share

Crap, all because I left position in. Thanks man, you're a life saver.

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

Prefabs aren't updated when run or built 1 Answer

MLAPI error with two instances of networked object 0 Answers

Assets couldn't be loaded 1 Answer

spawning rigidbodies next to each other 0 Answers

InvalidCastException when Instantiating with photon (PUN) 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