Home Unreal Engine

Rotating an object orientation towards the player in UDK.

Hey all,

Okay! So this may be a little confusing but I need to understand how to "code" something in UDK.
I need to have my grass alphas always face the player as he is walking around them. So, in L4D2 when you are walking around grass cards they always face you so you don't see the weird disappearing faces or the side of the alpha. I was thinking about trying to do something in the material editor because there is an 'object orientation node' but I do not know enough about it all.
If this makes sense and you can help me I would be very grateful.
Also, if anyone has any questions about this question ( if that makes sense :p ) let me know and I can elaborate about this more.
Screenshots will help also!
Thanks guys ( and gals )!
:D

Replies

  • Andrew Mackie
    I'm just typing here to see if anyone will notice this thread again.
    I really need help with this problem and I am nowhere near smart enough to figure it out on my own :]

    <3
  • ParoXum
    Offline / Send Message
    ParoXum polycounter lvl 9
    Well I guess the exact name of what you're seeking is sprites, I don't think you can make sprite based foliage in the UDK with the regular toolset tho.

    Maybe you can try to play with particles.
  • Andrew Mackie
    Thanks ParoXum! - I'll give particles a look through and see if I can figure them out in regards to this problem.
  • sprunghunt
    Offline / Send Message
    sprunghunt polycounter
    you can make a shader that makes a fake sprite by using world position offset.

    http://udn.epicgames.com/Three/WorldPositionOffset.html

    You need to make a material that rotates the vertexes of the model to face the player. It's a bit complicated for me to easily make an example so hopefully this will give you an idea and you'll come up with something yourself.
  • Andrew Mackie
    hey sprunghunt - thanks for the link. My problem is that I don't know how to make a material rotate towards the position of the player but hopefully I'll be able to work with this and figure it out. Thanks for the comments guys!
  • sprunghunt
    Offline / Send Message
    sprunghunt polycounter
    hey sprunghunt - thanks for the link. My problem is that I don't know how to make a material rotate towards the position of the player but hopefully I'll be able to work with this and figure it out. Thanks for the comments guys!

    well here's something else that might help:

    http://udn.epicgames.com/Three/MaterialsCompendium.html#RotateAboutAxis
  • Andrew Mackie
    I plugged in all the info as it describes with the object/material is not always facing the player as I move throughout the scene. I'll keep playing with this and see if I can post some screenshots or a video better explaining my problems haha. Thanks for all the help sprunghunt!
  • Andrew Mackie
    Still have not found out the proper way to do this yet.
    Got everything plugged into the correct spots, but the object will still not face the character as I walk around it.
    I'll try to get this working asap.
  • ImSlightlyBored
    Offline / Send Message
    ImSlightlyBored polycounter lvl 13
    test postx
    sorry this is playing up at work, already wrote a response that got lost.
    Basically
    you can do this three ways. In decreasing complexity.

    1) i think you'd need to transform the matrix for the vertex shader to get it to stick to screen. you cant do transforms through the built in nodes in to vertex shader (at least i dont think) so you will need to try and do that in custom node.

    I've done something similar to a vertex shader approach with this, by comparing the angle between object position and camera position, and rotating the asset accordingly. not ideal! and not really what you want, as it's not on a per plane basis.

    2) You could make a cheap particle system to do this for you? Particles also have a feature to orient a mesh towards a camera, not just a sprite. Don't think particles are instanced in UDK though.

    3) and finally... doesnt speedtree already have a feature for something like this? in the past i've definitely seen speedtree assets with billboards that face to camera.
  • Andrew Mackie
    Hey ImSlightlyBored! - Thanks man this is exactly what I need. I'm going to try the particle system first then I'll look into Speedtree and see if there is something I can do with that. Thanks again and I'll try to post my results soon.
  • ImSlightlyBored
    Offline / Send Message
    ImSlightlyBored polycounter lvl 13
    id be careful using particles, as i'd like to reiterate that i dont think epic's udk builds have instanced particles so this could get heavy (love to be proved wrong though!)
    i think speedtree is the number 1 route to go, if it does indeed do this.
  • A. Rabbit
    Offline / Send Message
    A. Rabbit polycounter lvl 10
    Thought I would post this, will probably help a few people wanting to make a billboard effect with static meshes.

    Drawbacks:

    - Does not take objects current rotation into account, meaning any custom Z rotation would break the billboard and become out of sync with the camera.

    - Only rotates around the objects Z axis.

    - Don't know how efficient this method is.


    Billboard material link:

    http://www.3dality.co.uk/UDK_Z-Axis_BillboardMaterial.jpg
  • Andrew Mackie
    Hey A. Rabbit! Thanks for the link! I'll look into trying that out and let you know if it's what I needed.
  • tomacmuni
    For the A. Rabbit expression, it works but probably not as intended.
    The rotation is not about the object z axis -- the video I posted on youtube
    shows this: [ame]http://www.youtube.com/watch?v=1kmLPZhtszQ[/ame]
    Also, it appears to work in the editor but on build and PIE the
    assets stay exactly where they were placed in the scene and nothing
    happens and the surface is black (I used first BSP cards then interpactor cards to try it out).
  • Andrew Mackie
    Hey tomacmuni! This is awesome, I'm going to try to figure this problem out again (it's been a while since I last tried). Thanks for the great help, I'll post my results soon!
  • tuxmask75
    Offline / Send Message
    tuxmask75 polycounter lvl 10
    Was anyone able to make billboards that always face the camera even while looking down from above? ( not just on the Z axis)
    I'm really in need on standard billboards.
  • ambershee
    Offline / Send Message
    ambershee polycounter lvl 17
    tuxmask75 wrote: »
    Was anyone able to make billboards that always face the camera even while looking down from above? ( not just on the Z axis)
    I'm really in need on standard billboards.

    Sprites?
  • tuxmask75
    Offline / Send Message
    tuxmask75 polycounter lvl 10
    Yeah for Sprites! :)
    I been playing with A.RABBITS code all day.
    Looks like something is missing here, but what ?
    Would love to know how to rotate around the other 2 axis.
    (yeah ,1 more axis is enough but knowing the other 2 would be great)
    float4 output;
    float3 CameraToObjVector;
    //Get Camera to Object Vector
    CameraToObjVector = normalize(CameraWorldPos - ObjectWorldPositionAndRadius);
    //Set RGB of output to the objects Z-Axis
    output.r = ObjectOrientation.r;
    output.b = ObjectOrientation.b;
    output.g = ObjectOrientation.g;
     
    //Transform Vector into Radians.
    output.a = atan2(CameraToObjVector.y,CameraToObjVector.x);
    return (output);
    
  • b1skit
    Any updates on this guys? I'm also looking for a billboard system for grass, so that the planes always face the player/camera.

    I read someone mentioning you can set your mesh to the lowest LOD setting?
  • b1skit
    Nope, that doesn't work... Does the A.RABBITS code work as described, or is it as broken as it looks in tomacmuni's video?

    Cheers.
  • tuxmask75
    Offline / Send Message
    tuxmask75 polycounter lvl 10
    yeah I'm still looking for this too,,, model always facing the camera, for true in your face billboards...

    A rabbits system works for me as is , just a billboard that rotates left and right if u pan the cam left and right.
  • b1skit
    Seems A.RABBITS code works, and workds quite well... But, with a few caveats:

    - The effect is broken when the material is applied to a mesh used in foliage mode. The same mesh/material works perfectly as a billboard as a static mesh, but rotates through the air (rather that simply angling its face towards the camera) when used in foliage mode. I'm guessing this has something to do with the world position somehow being reported as the origin of the landscape, instead of the actual correct location of the mesh... Maybe someone with more material editor know-how can tweak it to work in foliage mode?

    - The material doesn't work if applied as a material to a LOD mesh. This is disappointing, as it would have the most potential in this situation (at a certain distance from the camera, swap in a billboard material plane in place of the higher poly geo)

    Wonder if anyone else can figure out how to tweak this for perfection?

    For now, it seems the best bet for my scene is to use foliage mode (Rather than hand place an entire field made of 5 different grasses...), which rules out the billboard material for now :(
  • MarianneM
    I got this problem when I did the costume nod: vertex shader use too many constant

    Nevermind the material was traluscent switched to masked work fine now
  • r4ptur3
    Offline / Send Message
    r4ptur3 polycounter lvl 10
    not sure if this will help at all, but I got the material on page 10 to work a long time back

    http://udn.epicgames.com/Three/rsrc/Three/DirectX11Rendering/MartinM_GDC11_DX11_presentation.pdf

    It is UV dependent -- make sure the card's UVs fill the whole 0-1 space. Again, this was a long time ago so who knows if it still works.
  • ktacreations
    So would it be too much to ask for a material that makes an object always try to point one of its axis to world-up? Also why does any of this require scripting at all? Isnt this functionality that should have been in UDK since the first build? It's been used in games since 1997.
Sign In or Register to comment.