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 AmazingB · Jan 04, 2014 at 02:11 AM · vector3vectorfloats

Checking if a Vector3 is a int

I want to make make my character walk back if he walks into a stone or a tree in a grid based game.

here is my script :

var startPoint : Vector3;
var endPoint : Vector3;
var speed : float;
private var increment : float;
var isMoving : boolean;
var tileSpace : float;
var tileOn : String;
var tile : GameObject [];
var tileStatts; var walkedDir : Vector3;

function Start () {

 startPoint =  transform.position;
 endPoint = transform.position; 


}

function Update () {

 var pos = transform.position;
 
 calculateTileOn ();
 
 
 if(tileOn == "Tree" || tileOn == "Stone"){
     increment = 0;
     isMoving = true;
         switch (walkedDir){
         case Vector3.up :
         startPoint = transform.position;
         endPoint = new Vector3(transform.position.x, transform.position.y - tileSpace, transform.position.z );
         break;
         case Vector3.down :
         startPoint = transform.position;
         endPoint = new Vector3(transform.position.x, transform.position.y + tileSpace, transform.position.z );
         break;
         case Vector3.left :
         startPoint = transform.position;
         endPoint = new Vector3(transform.position.x - tileSpace, transform.position.y, transform.position.z );
         break;
         case Vector3.rigth :
         startPoint = transform.position;
         endPoint = new Vector3(transform.position.x + tileSpace, transform.position.y - tileSpace, transform.position.z );
         break;
         
     }
         
 }
 
 
 
 
 if(increment <=1 && isMoving == true){
     increment += speed/100;
     }
 else{
     isMoving = false;
 
 }
 if(isMoving){
     transform.position = Vector3.Lerp(startPoint, endPoint, increment);
     
 }
 if(Input.GetButton("forward") && isMoving == false){
     increment = 0;
     isMoving = true;
     startPoint = transform.position;
     endPoint = new Vector3(transform.position.x, transform.position.y + tileSpace, transform.position.z );
     walkedDir = Vector3.up;
     
 }    
 
 if(Input.GetButton("backward") && isMoving == false){
     increment = 0;
     isMoving = true;
     startPoint = transform.position;
     endPoint = new Vector3(transform.position.x, transform.position.y - tileSpace, transform.position.z );
     walkedDir = Vector3.down;
 }    
 
 if(Input.GetButton("left") && isMoving == false){
     increment = 0;
     isMoving = true;
     startPoint = transform.position;
     endPoint = new Vector3(transform.position.x - tileSpace, transform.position.y, transform.position.z );
     walkedDir = Vector3.left;
 }    
 
 if(Input.GetButton("rigth") && isMoving == false){
     increment = 0;
     isMoving = true;
     startPoint = transform.position;
     endPoint = new Vector3(transform.position.x + tileSpace, transform.position.y, transform.position.z );
     walkedDir = Vector3.rigth;
 }    
 




}

function calculateTileOn() {

  var hit: RaycastHit2D = Physics2D.Raycast(transform.position, -Vector2.up);
     
     if(1 == 1){
         tileOn = hit.collider.gameObject.tag;
         tile =  GameObject.FindGameObjectsWithTag (tileOn);
         tileStatts = tile.Tile;
         
         
     }
     
     
     
         

}

Could you tell me how to change my script so that the character walks back when it is on a int (center of a Tile).

And could you also tell me what I am doing different with my rigth, because it says Object reference not set to an instance of an object when I press my rigth key.

Comment
Add comment · Show 4
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 BigRoy · Jan 04, 2014 at 10:49 PM 0
Share

About your right problem. rigth should be right.

avatar image AmazingB · Jan 04, 2014 at 10:53 PM 0
Share

Ups, but that is not the problem, because my input is also set to rigth.

avatar image tanoshimi · Jan 04, 2014 at 10:57 PM 1
Share

It is a problem, because of walkedDir = Vector3.rigth;

avatar image AmazingB · Jan 04, 2014 at 11:05 PM 0
Share

Ups again.

0 Replies

· Add your reply
  • Sort: 

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

20 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 avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Make an FPS gun point at the mouse position. 2 Answers

Vector3 Projection 2 Answers

Rotating a character's velocity? 3 Answers

Getting (Input) values before running rest of script. 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