Professional Web Applications Themes

Character gravity - Macromedia Director 3D

Hi, could someone plaese tell me where i am going wrong here.....I am trying to create some simple gravity effects...so that when the character walks off a surface, he falls to the ground...but my attempts so far have produced strange results: on alignToTerrain locationVector2 = bongoWorld.model("joint70-skeleton").worldPosition locationVector2.y = bongoWorld.model("joint70-skeleton").worldposition.y + 5 directionVector2 = vector(0,-1,0) col2 = bongoWorld.modelsUnderRay(locationVector2,directio nVector2,2,#detailed) if col2.count>0 then repeat with j=1 to col2.count if (col2[j].model <> bongoWorld.model("joint70-skeleton")) then bongopos = col2[j].isectPosition.y +3.7721 if (col2[j].distance > 3.7721) then bongoWorld.model("joint70-skeleton").translate(0,-2,0) else bongoWorld.model("joint70-skeleton").worldposition.y = bongopos end if end if end repeat end if end The alignToTerrain function is called in ...

  1. #1

    Default Character gravity

    Hi, could someone plaese tell me where i am going wrong here.....I am trying to
    create some simple gravity effects...so that when the character walks off a
    surface, he falls to the ground...but my attempts so far have produced strange
    results:

    on alignToTerrain
    locationVector2 = bongoWorld.model("joint70-skeleton").worldPosition
    locationVector2.y = bongoWorld.model("joint70-skeleton").worldposition.y + 5
    directionVector2 = vector(0,-1,0)
    col2 =
    bongoWorld.modelsUnderRay(locationVector2,directio nVector2,2,#detailed)
    if col2.count>0 then
    repeat with j=1 to col2.count
    if (col2[j].model <> bongoWorld.model("joint70-skeleton")) then
    bongopos = col2[j].isectPosition.y +3.7721
    if (col2[j].distance > 3.7721) then
    bongoWorld.model("joint70-skeleton").translate(0,-2,0)
    else
    bongoWorld.model("joint70-skeleton").worldposition.y = bongopos
    end if
    end if
    end repeat
    end if
    end
    The alignToTerrain function is called in an enterframe loop.

    thanks very much for your time

    Richard

    Richard.B Guest

  2. #2

    Default Re: Character gravity

    i think you should calculate a little tolerance into your script.

    every frame you fall you go down about -2 worldunits and you are something
    about 3.7721 over the ground. at the moment i have no idea what happens in your
    scene or what you ment by strange results. at the moment i am thinking about
    the size of the models. i use cinema4D for modelscreations and the standard box
    is about 200 units big.
    if i use a downvector of (0,-2,0) it is quite slow, if your models are in
    sizes of 5 or 2 wordunits you are pretty fast.

    and your ray can detect two models at the same time and i would try to use
    only the first one in the col2 list.
    "col2 =
    bongoWorld.modelsUnderRay(locationVector2,directio nVector2,1,#detailed)"

    and what should happen if you have stairs?

    you need something for falling and something for going up.

    alist = member("3dwelt").modelsUnderRay(pEgoposition, vector( 0,-1, 0), 1,
    #detailed)

    repeat with i in alist
    a=(i.isectposition)
    c=i.model
    d=integer(i.distance)
    e=i.isectNormal
    end repeat

    h?he=150
    fallh?he=250
    uph?he=140
    b=vector(0,-50,0)
    bb=vector(0,1,0)
    f=h?he+a.y+up

    if string(c) contains "*" then
    backvec=pEgo.transform.position
    if d<=fallh?he then
    pEgo.translate (transvec)
    pEgo.transform.position.y=f
    else if d>fallh?he then
    pEgo.translate (transvec+b)
    else if d<uph?he then
    pEgo.translate (transvec+bb)
    end if
    else if string(c) contains "#" then
    pEgo.transform.position=backvec
    end if

    hondo3000 Guest

  3. #3

    Default Re: Character gravity

    use removeFromWorld() to remove your character model before casting the ray
    into the ground, then use addToWorld() to add the character back in again.
    Do this every frame. Otherwise if the ray hits the character and not the
    ground you will miss collision data here and there, and the model could fall
    through the floor. This will also speed up the raycast massively.

    Also you don't have to fire the ray from the postion of the character. Just
    set the ray origin pos to the x and z of your character world position and
    use a y value at a constant height well above the highest point of your
    terrain. That way the ray will never "miss". Given the known height of the
    ray origin you can work out the world position of the intersection.

    A trick mentioned on this site a lot is to add every model that you don't
    want to cast the ray against to a group object, then remove the group, cast
    the ray, add back the group. That way all the unwanted objects will be
    ignored.

    Also the latest version of Director has a raycast where you can specify a
    list of models to check against. This is even better, but I still use 8.5 as
    it hasn't been worth upgrading for years.

    Cheers

    Richard


    Richard Guest

  4. #4

    Default Re: Character gravity

    and take a look at the livedocs of modelsunderray, for a description or more
    options you can use with the ray.

    and if you want to make some kind of "gravity like" falling, with a little bit
    of physic behavior, you can take a look at this littel example.
    [url]http://kisd.de/~lutz/crap/jump/[/url]

    the code is not very long and you can make it work in 3D. just press on the
    space bar and see how it works, its very simple and you can see all the code.

    to richard:
    if the ray is not send from the position of the character, it is not possible
    to make more than one level where you can move, if there are more levels above
    each other and you climb stairs and these things it will become difficult to
    manage this with a fixed high. i think about going under an object.
    if there is only one level it should work fine.

    regards!

    hondo3000 Guest

  5. #5

    Default Re: Character gravity

    > to richard:
    > if the ray is not send from the position of the character, it is not
    > possible
    > to make more than one level where you can move, if there are more levels
    > above
    > each other and you climb stairs and these things it will become difficult
    > to
    > manage this with a fixed high. i think about going under an object.
    > if there is only one level it should work fine.
    Very true! Was assuming (maybe wrongly) a single terrain object.

    Cheers

    Richard


    Richard Guest

  6. #6

    Default Re: Character gravity

    Hey...thanks for all the replies guys......i will take a look at them now....

    to: hondo3000
    you are absolutely right about sending the ray from the position of the
    character, the enviroment that the character walks around in has multi-levels,
    with stairs etc...

    thanks again guys

    Richard.B Guest

Similar Threads

  1. gravity help
    By bobstarlau in forum Macromedia Director 3D
    Replies: 1
    Last Post: August 17th, 06:21 AM
  2. Havok Collision in zero gravity
    By Skavengur in forum Macromedia Director 3D
    Replies: 5
    Last Post: August 17th, 02:57 AM
  3. 3d world gravity
    By keogan in forum Macromedia Director 3D
    Replies: 0
    Last Post: July 25th, 02:41 PM
  4. Gravity problem
    By openspark in forum Macromedia Director 3D
    Replies: 1
    Last Post: April 28th, 07:19 PM
  5. realistic gravity
    By olavi lappalainen in forum Macromedia Director 3D
    Replies: 2
    Last Post: October 9th, 03:48 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139