Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Can't change Constant Force component

Discussion in 'Scripting' started by School73, Feb 23, 2015.

  1. School73

    School73

    Joined:
    Feb 13, 2015
    Posts:
    8
    Hi!
    I have wrote this script:
    using UnityEngine;
    using System.Collections;

    public class BallMove : MonoBehaviour {
    // Use this for initialization
    void Start () {
    ConstantForce cf = GetComponent<ConstantForce>();
    cf.force.Set(0,0,1000);
    }

    // Update is called once per frame
    void Update () {

    }
    }
    and attach it to my GameObject that have ConstantForce component.
    But, after launching this script not change anything.
    I tried to debug: variable cf get a link to right component, but after
    cf.force.Set(0,0,1000); nothing happend.
    What is it? Help me, please.

    P.S. Sorry for my English.
     
  2. gamer_boy_81

    gamer_boy_81

    Joined:
    Jun 13, 2014
    Posts:
    169
    You need to add a rigidbody also to that gameobject.
     
  3. School73

    School73

    Joined:
    Feb 13, 2015
    Posts:
    8
    Of course I did it! ))
     
  4. gamer_boy_81

    gamer_boy_81

    Joined:
    Jun 13, 2014
    Posts:
    169
    ok, just wanted to make sure :)

    Also, need to make sure that isKinematic is not enabled.

    I've never seen force.Set()..how about
    directly setting the value like this :

    cf.force = new Vector3(0, 0, 1000);
     
  5. School73

    School73

    Joined:
    Feb 13, 2015
    Posts:
    8
    yeah, thank you. it works.
     
  6. gamer_boy_81

    gamer_boy_81

    Joined:
    Jun 13, 2014
    Posts:
    169
    Glad it worked..wondering which one worked...isKinematic or removing the Set() function ?
     
  7. School73

    School73

    Joined:
    Feb 13, 2015
    Posts:
    8
    Second one.