x


Move FPS up/down one level in a building

Hi there,

I am actually using Player Relative Control Prefab from the Standard Assets (Mobile) Folder and i have a 3D model that have a few storey. The problem here is i am trying to move the character (Player Relative Control) Up/Down one storey upon clicking on the GUI Button of 'Up' or 'Down' respectively. But i would need to click on the 'Down' a few time before the character will actually move down by one storey. I am using the following Code:

 character.transform.Translate(new Vector3(newPositionX, newPositionY, newPositionZ) * Time.deltaTime);

Someone can kindly advice me on what i should do to resolve this?

Thanks in advance!

Below is a sample of my problem code which should fire of when i click on the Button:

 if (GUI.Button(new Rect(10, 60, 80, 30), "Down")) {
 
                 //AutoFade.LoadLevel(null, 0, 1, Color.black);
 
                 Debug.Log("Before current position: " + character.transform.position.y);
 
                 for (int i = 0; i < floorHeightArrayList.Count; i++) {
 
                     if ((character.transform.position.y - 1) <= float.Parse(floorHeightArrayList[i].ToString())) {
 
                         /*if ((character.transform.position.y - 1) == float.Parse(floorHeightArrayList[i].ToString())) {
 
                             newPositionX = character.transform.position.x;
 
                             newPositionY = float.Parse(floorHeightArrayList[i + 2].ToString()) + 1.0f;
 
                             newPositionZ = character.transform.position.z;
 
                     
 
                             character.transform.position = new Vector3(newPositionX, newPositionY, newPositionZ);
 
                             break;
 
                         }*/
 
                         
 
                         newPositionX = character.transform.position.x;
 
                         newPositionY = float.Parse(floorHeightArrayList[i - 1].ToString()) + 1.0f;
 
                         newPositionZ = character.transform.position.z;
 
                         
 
                         //Debug.Log("newPositionY: " + newPositionY);
 
                         
 
                         character.transform.Translate(newPositionX, newPositionY, newPositionZ, Space.Self);
 
                         //character.transform.position = new Vector3(newPositionX, newPositionY, newPositionZ);
 
                         break;
 
                     }
 
                 }
 
                 Debug.Log("After current position: " + character.transform.position.y);
 
             }

                     
more ▼

asked Nov 02, 2011 at 02:39 AM

R-GiGgS84 gravatar image

R-GiGgS84
31 24 21 24

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

if you want to instantly jump one floor when clicking the button, there's no reason to multiply by deltaTime. You do that when you want to move at some steady rate over time, as in an update() function, and you multiply deltaTime by the velocity, not by a target position.

Assuming newPositionX/Y/Z are the point you want to go to one floor up/down, just remove the "*Time.deltaTime" bit entirely.

more ▼

answered Nov 02, 2011 at 03:38 AM

WillTAtl gravatar image

WillTAtl
822 7 9 18

hi WillTati,

Thanks for the reply. I want the character to like slowly move up/down one level. Currently i am trying on the following codes:

character.transform.Translate(newPositionX, newPositionY, newPositionZ, Space.World);

But it don't seem to have the 'feel' of the character is move up/down.

Nov 02, 2011 at 03:54 AM R-GiGgS84

ah, sorry for the misunderstanding. I'm afraid I don't understand what's happening or what you're asking, then. Where are you using this line of code? In what function, and on what conditions?

It might help if you could add the entire function containing this line to the original question, instead of giving just this one line!

Nov 02, 2011 at 04:01 AM WillTAtl

Hi WillTatI,

Sorry for my poor explaination. I have attached above for the code that is suppose to fire off in a GUI Button.

Nov 02, 2011 at 04:05 AM R-GiGgS84

it sounds like you want an elevator, but without the elevator? Search UA for questions about elevators, they should be helpful, you'll just be applying the behavior to the player directly instead of to an elevator object!

Nov 02, 2011 at 02:13 PM WillTAtl
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1657
x377
x91
x76
x12

asked: Nov 02, 2011 at 02:39 AM

Seen: 950 times

Last Updated: Nov 02, 2011 at 02:13 PM