No announcement yet.

(Help) How to update movement direction depending on mouse.

  • Filter
  • Time
  • Show
Clear All
new posts

    (Help) How to update movement direction depending on mouse.

    Hello people,

    I'm working with the physics ball bp blueprint template adding to the third person camera included. I added movement to the camera with the mouse so you can look to the sides and also up and down but I've encountered some problems that I need help with.

    1- First and most important, if I look to the right and press w to move forward the ball moves to the left since the player rotation didn't change depending on where the mouse was looking. I want to be able to move forward towards the direction that the player is pointing.

    2- The camera clips trough everything so you can see inside the floor and walls. I played around with the "do collision test" in the camera collision tab but then it collides with everything. Is there a way to make the camera collide with only certain objects in the scene?

    3- If I keep moving the mouse up or down I clip trough the ground or see the player directly from the top. I know one can use clamps in order to stop the camera if it reaches a certain pitch but I can't get it to work for some reason.

    I'll appreciate any help with this topics. Thanks

    Here's a screenshot of the blueprint that focuses on the camera movement.

    Click image for larger version

Name:	Ball_blueprint.jpg
Views:	1
Size:	46.3 KB
ID:	1171122

    Click image for larger version

Name:	Ball_camera_clipping_trough _ground.jpg
Views:	1
Size:	49.3 KB
ID:	1171123

    get forward and right vectors from camera arm, project both of those vectors onto horizontal plane (normal vector [0,0,1]). Now you should have 2 vectors that are always horizontal. Normalize those vectors, this removes diagonal speed up bug.
    on event tick: you have 2 axis inputs (same names as your axis input events but function that gives only value without calling event, green names) for move forward and move right. multiply them by vectors: forward_input * [1,0,0], right_input*[0,1,0] add both results together.
    Now you have your move vector, and there is node that works just like move forward (or add input) but adds move vector, i just forgot exact name , so you need to look for it, it is in same category in palette as pawn add input.
    So on event tick you feed that calculated move vector to moving node.

    did not found simple way for it. I am doing topdown game, and all actors (walls etc) when they detect they are under camera they just set self to transparent. I am using blueprintable actor component that hooks camera location and hides/shows actor its attached to. Search for blueprintable components, create one. Make it read camera location and camera forward vector. Project both on floor. then find horizonta distance of actor from camera. and check if its in camera forward cone. Bit of vector math. For now just remove objects that collide with camera from level. Develop gameplay and movement now. Worry about such stuff like hiding actors later.

    Best way for it: dot product (it is cosinus of angle between 2 vectors)
    Take 2 vectors: camera forward vector and [0,0,1]. get their dot product.
    Print that result in runtime, note values beetwen whixh you want camera to pitch, then do not rotate camera outside that value.

    Ps. I think camera pitch is easiest task here, you should start with it. Moving (ie 1st problem) is bit more complicated version of camera clamping.
    PPS. I may post pictures of those blueprints later today, I made similar code to described for my project.


      Thank you I'll work on it but yeah if you post pictures that would also help. Thanks a lot!


        dang i forgot yestarday.


          Hahaha It's ok. I could solve problem 3 but still problem 1 & 2 persist.


            Could you work on the blueprints pictures?