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 Noah Bangs · Jul 18, 2012 at 08:01 PM · c#movement

The Sims-like movement script?

I need help making a script to make a character move around like in the sims. The one me and my programmer made just teleports the character to an unknown location. we are making a game called Reality, which is like The Sims. I would like it in C#.

Any Help?

edit: Here is the code:


using UnityEngine; using System.Collections;

public class ConstrainToTerrain : MonoBehaviour

{

bool canMove = false; public int speed = 5; RaycastHit hit; //Create an object to store all the raycast data Vector3 groundedHitPoint;

void Start() {}

void OnCollisionEnter () { if (Collision.gameObject.tag == "Terrain" ) { canMove = false; } //else //{ //canMove = true; //} }

void Update() { if(Input.GetMouseButton(1)) {
//create a new ray from the source point from the camera to the mouse position Ray ray = (Camera.main.ScreenPointToRay(Input.mousePosition));

      //ray is the origin and vector, and out hit is a vector, passing by reference so it needs out keyword
         if (Physics.Raycast(ray, out hit)) 
      {
             //Debug.Log("Hit: " + hit.transform.name);
           if (hit.transform.name == "Terrain")
              {
                Debug.DrawLine(Camera.main.transform.position, hit.point);
              }
       //have the cube turn to face the point

       groundedHitPoint = hit.point;
       groundedHitPoint.y = 1;
       transform.LookAt(groundedHitPoint);
       //Debug.Log("groundedhitpoint is : " + groundedHitPoint);
       canMove = true;
        }

    }
 if (canMove)
 {

    //this moves an object
    transform.Translate(Vector3.forward*Time.deltaTime*speed);
    //Debug.Log ("Vector3.forward is: " + Vector3.forward);
    //GameObject.FindWithTag("ScavengerSprite").transform.position.y.Equals(1000);

    float  distance = Vector3.Distance(transform.position, groundedHitPoint);
    if (distance <= 0.1F)
    {
      canMove = false;
    }
 }

} }`enter code here`

Comment
Add comment · Show 2
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 IndieScapeGames · Jul 18, 2012 at 08:36 PM 0
Share

Unity Answers isn't a job posting site like asking someone to code something for you. Ins$$anonymous$$d, provide a snippet of code, or something to help comment on.

For collaboration like you're asking, better to post in the Unity forums:

http://forum.unity3d.com/forums/17-Collaboration

avatar image Noah Bangs · Jul 18, 2012 at 08:52 PM 0
Share

but I do have code, Chad$$anonymous$$.

I posted it just now.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by DaveA · Jul 18, 2012 at 08:57 PM

Maybe these?

http://unifycommunity.com/wiki/index.php?title=Click_To_Move

http://unifycommunity.com/wiki/index.php?title=ClickCharacterController

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Making a bubble level (not a game but work tool) 1 Answer

Camera Script - Bird's Eye View 1 Answer

Character getting stuck on curbs.. 0 Answers

C#:Unity:Having trouble reference Rigidbody2d from different script 2 Answers

Distribute terrain in zones 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