• 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 Daniel 8 · Jun 27, 2010 at 07:24 AM · ball

Help with making a ball rotate!

Hey I just need help with adjusting my script, I have it so it has a Transform.Addforce but that doesn't work, here my script is:

var speed = 3.0; var rotateSpeed = 3.0; var bullitPrefab:Transform;

function Update () { var controller : CharacterController = GetComponent(CharacterController);

 transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);

 var forward = rigidbody.AddForce(Vector3.left *20);
 var curSpeed = speed * Input.GetAxis("Vertical");
 controller.SimpleMove(forward * curSpeed);

 if(Input.GetButtonDown("Jump")) {
     var bullit = Instantiate(bullitPrefab, 
     GameObject.Find("spawnPoint").transform.position, 
         Quaternion.identity);

 bullit.rigidbody.AddForce(transform.forward * 200);
 }

} @script RequireComponent(CharacterController)

I have 2 errors that both revolve around the AddForce and Transform

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

1 Reply

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

Answer by Ashkan_gc · Jun 27, 2010 at 08:12 AM

why do you write code like this. just add a rigidbody and don't add a character controller. add a sphere collider to the ball and then use rigidbody.AddForce and AddTorque to add forces to your ball. AddForce is good for most situations. take a look at this ball movement and jump script

using UnityEngine;

public class ball : MonoBehaviour

{ RaycastHit h; public float jumpPower=10; public float maxspeed = 20; //max allowed speed public float speed=300; //acceleration public float ratio = 2; //ratio of x axis speed compared to z axis public static int coins; Vector3 v;

void Awake() { Camera.mainCamera.transform.position = new Vector3(transform.position.x, transform.position.y+10 , transform.position.z - 3.5f); Camera.mainCamera.transform.LookAt(transform); }

void LateUpdate() {

 Camera.mainCamera.transform.position = new Vector3(transform.position.x,transform.position.y+6,transform.position.z-15);
 Camera.mainCamera.transform.LookAt(transform);

}

void FixedUpdate() { v.x = transform.position.x; v.y = transform.position.y-0.56f; v.z = transform.position.z; if (Input.GetKeyDown (KeyCode.Space)) { if (Physics.Linecast(transform.position, v, out h) == true) { rigidbody.AddForce(0, 150 + (rigidbody.velocity.magnitude*jumpPower), 0); } } if (rigidbody.velocity.magnitude < maxspeed) rigidbody.AddForce (Input.GetAxis ("Mouse X")*speed/ratio, 0, Input.GetAxis("Mouse Y")*speed); } void OnGUI() { GUI.Label (new Rect (30,50,300,100),coins.ToString());

}

}

Comment
Add comment · Show 5 · 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 Ashkan_gc · Jun 27, 2010 at 08:13 AM 0
Share

there is additonal complexity of raycasts to see if the ball is on the ground then it can jump. i never completed this game but this script posted many times in this site :)

avatar image Daniel 8 · Jun 27, 2010 at 09:48 AM 0
Share

It says your script hasn't finished compilations yet?

avatar image Ashkan_gc · Jun 28, 2010 at 03:07 AM 0
Share

@$$anonymous$$ the script works well! is there any probelm? you might forgot to attach a rigidbody and a sphere collider to the object.

avatar image Daniel 8 · Jun 29, 2010 at 05:29 AM 0
Share

Thank you sooooooo much, this is just perfect, i greatly appreciate your help :D

avatar image Ashkan_gc · Jun 29, 2010 at 07:36 AM 0
Share

you are welcome man!

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

bouncing ball without physics/gravity 2 Answers

rolling ball is a child that needs to be steered by parent 1 Answer

How to roll a ball ? 2 Answers

pong rolling ball 1 Answer

Best way to achieve Sonic style physics? 0 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