Page 2 of 2 FirstFirst 12
Results 11 to 18 of 18
  1. #11
    Join Date
    Apr 2007
    Location
    Seattle
    Posts
    214
    Quote Originally Posted by BrumDogPro View Post
    I tried your script out. It's pretty good. The only problem was the cube ran through the terrain if it was raised haha
    Yeah I had to attach the cube to an empty gameobject and make that one the mover in order to not have it fall though the floor. This was just ment to be a starting point, not the final code by any means. I think I'll try LampNick's suggestion and attach a charactercollider to it when i get home and see what happens.

  2. #12
    Join Date
    Feb 2011
    Posts
    27
    Quote Originally Posted by Lerich View Post
    Yeah I had to attach the cube to an empty gameobject and make that one the mover in order to not have it fall though the floor. This was just ment to be a starting point, not the final code by any means. I think I'll try LampNick's suggestion and attach a charactercollider to it when i get home and see what happens.
    I tried to add a character collider to my cube and it did nothing. It still sunk into the ground. Ill play around with the script and see what I can do.

  3. #13
    Join Date
    Aug 2010
    Location
    Aegina
    Posts
    36
    Quote Originally Posted by BrumDogPro View Post
    I tried to add a character collider to my cube and it did nothing. It still sunk into the ground. Ill play around with the script and see what I can do.
    the CharacterCollider is most to apply the Gravity and use the options that it gives you later..

    and for the sinking think it more carefully

    Code:
     mover.position = Vector3.MoveTowards(mover.transform.position, destination, Time.deltaTime * 10);
    destination is the Raycast point right... is a Vector3(x, y, z). the problem is that the y has the same value of where u clicking that means the floor's tranform.position.y.
    and if your cube's pivot point is in the center the cube will sink because the transform.position.y of the cube is set to the floor's transform.position.y.

    a way to fix that is that the second value at the MoveTowards is like that
    Code:
    mover.position = Vector3.MoveTowards(mover.transform.position, new Vector3(destination.x, mover.transform.position.y, destination.z) , Time.deltaTime * 10);
    not 100% sure test and tell me..

    but with this u will never get higher or lower.. that's why u have to apply gravity i am not sure but moving him in x and z it will force him to go higher and also the gravity will force him to go lower.
    this is just the way i imagine it nothing sure..

  4. #14
    Join Date
    Feb 2011
    Posts
    27
    Quote Originally Posted by LampNick View Post
    the CharacterCollider is most to apply the Gravity and use the options that it gives you later..

    and for the sinking think it more carefully

    Code:
     mover.position = Vector3.MoveTowards(mover.transform.position, destination, Time.deltaTime * 10);
    destination is the Raycast point right... is a Vector3(x, y, z). the problem is that the y has the same value of where u clicking that means the floor's tranform.position.y.
    and if your cube's pivot point is in the center the cube will sink because the transform.position.y of the cube is set to the floor's transform.position.y.

    a way to fix that is that the second value at the MoveTowards is like that
    Code:
    mover.position = Vector3.MoveTowards(mover.transform.position, new Vector3(destination.x, mover.transform.position.y, destination.z) , Time.deltaTime * 10);
    not 100% sure test and tell me..

    but with this u will never get higher or lower.. that's why u have to apply gravity i am not sure but moving him in x and z it will force him to go higher and also the gravity will force him to go lower.
    this is just the way i imagine it nothing sure..
    I still got the sinking problem. And now that i actually look at the problem, its not sinking halfway down everywhere it goes like some people think. In fact, it looks like it staying at the same y value no matter what. It moves appropriately but doesnt adjust up and down at all.

  5. #15
    Join Date
    Feb 2011
    Posts
    27
    Ok I figured this one out. I took your code:

    Code:
    mover.position = Vector3.MoveTowards(mover.transform.position, new Vector3(destination.x, mover.transform.position.y, destination.z) , Time.deltaTime * 10);
    And I changed the "mover.transform.position.y" into "destination.y". :

    Code:
    mover.position = Vector3.MoveTowards(mover.transform.position, new Vector3(destination.x, destination.y, destination.z) , Time.deltaTime * 10);
    So instead of leaving y the way it is, I change it to equal the y value of the location clicked by the mouse.(Sorry if Im a little off on what Im saying)

    It still gets a little sinking effect but with tweaking to the character controller it can be fixed. The Real Glitch is when you click from flat surface to a flat surface on the other side of a hill... It will go through the hill to reach that point.

    Here's my video I just made. Its crappy quality but it gets the point across. This is with the edited script:

    Last edited by BrumDogPro; 03-03-2011 at 09:27 PM.

  6. #16
    Join Date
    Aug 2010
    Location
    Aegina
    Posts
    36
    it's really simple because the MoveTowards translate the mover from a vector to an other vector...
    anything u do with method u always have that problem...

  7. #17
    Join Date
    Feb 2011
    Posts
    27
    Quote Originally Posted by LampNick View Post
    it's really simple because the MoveTowards translate the mover from a vector to an other vector...
    anything u do with method u always have that problem...
    Couldnt something be added where it keeps the y value of that of the terrain?

  8. #18
    Join Date
    May 2013
    Posts
    1
    Thanks a lot Lerich, that script is perfectly working for me.
    I'm still trying to attach a plane following the ground to the cursor (a bit like in googlemap when you're in street view), and for that I use a javascript script.
    Both scripts are working when i use them alone, but when I plug the script managing the plane on the floor, your script stop working.
    Her is the script I'm using

    #pragma strict

    var plane: Plane;
    var drag: boolean = true;
    var position : Vector3;


    function Update(){

    plane = new Plane(Vector2.up, transform.position);
    drag = true; // start dragging

    position = transform.localPosition;

    if (drag){ // while drag is true, object follow the mouse pointer
    var ray: Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    var distance: float;
    if (plane.Raycast(ray, distance)){
    // transform the distance returned in a 3D point
    transform.position = ray.GetPoint(distance);
    }
    }
    }



    It would be very helpful if you had any idea of where the problem commes from.


    Cheers

Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •