Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
Sign in to follow this  
MrGohut

Create object which move only by X and Z

Question

I have this:

Please login or register to see this code.

i using it for create a Cube

Please login or register to see this code.

but after create i can move it by x, z and y i want do it only in X and Z. This object must be "attached" to the ground. Can u help me ?

Share this post


Link to post
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Friend you can freeze vector in inspector panel - x, y or z.

or you can vector.y define by a constant : transform.position.y Null

Share this post


Link to post
Share on other sites

  • 0

It's not a problem. Value which you choose will be a constant - 75 in your example.
But in your code I don't see anything about movement. Do you have created a controller?
Try to redefine in inspector (game object cube) the constraints which are mentioned with rigidbody (freeze position y).
I think it's the better way without code. Try it :

 

Please login or register to see this link.

Share this post


Link to post
Share on other sites
  • 0

Ye i have 1st person controller. This code just build a Cube and choose position to place it.

Ok, it freeze Y but after i hit "V". I need to do this when its attached to the main camera, look:

I click B, Cube spawn in front of me, attached to main camera and here i need to move it only by X and Z, y must be like the terrain (all the time Cube must adhere to terrain) and after i click V it change parent to null and Cube stay on terrain.

 

I want to do it like in Rust game.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...