Results 1 to 7 of 7
  1. #1

    Question Make the pawn look at the cursor (sidescroll)

    Hello,

    I am making a 2D sidescroller game (to learn the basics of UnrealScript) and the camera is setup and the pawn moves like I want.
    But I want it to aim at the cursor, my cursor is defined by 3d vector and already displayed on the screen.
    So now I need to find the delta of the pich and yaw but I don't now how to achieve that because I don't know what function I can use to direct the aim.
    What can i do ?

    Best regards,

    rXp>!<

  2. #2
    MSgt. Shooter Person
    Join Date
    Mar 2011
    Location
    Norway
    Posts
    70

    Default

    I think I've done something similar once.
    Take a look at what I did in this post.

    There's also a Youtube-clip showing my results - see if it's what you want.

  3. #3

    Default

    Quote Originally Posted by Ompakim View Post
    I think I've done something similar once.
    Take a look at what I did in this post.

    There's also a Youtube-clip showing my results - see if it's what you want.
    Seeing the video, yes that is what I'm looking for Thank you a lot
    And I see that our code are think the same way so the changes are extremely little !
    Thank you a lot

  4. #4

    Default

    The code seems correct but the mouse coordinate seems wrong.
    The issue is that that the mouse should be in the center (x and y axis) of the screen for the pawn to turn BUT the cursor think he is at the center way before the actual center.
    Screenshot :
    And the only change made on the actual position is this one :
    event PlayerInput(float DeltaTime)
    {

    // Add the aMouseX to the mouse position and clamp it within the viewport width
    mousePosition.X = Clamp(mousePosition.X + aMouseX, 0, 1920);
    // Add the aMouseY to the mouse position and clamp it within the viewport height
    mousePosition.Y = Clamp(mousePosition.Y - aMouseY, 0, 1080);
    super.PlayerInput(DeltaTime);
    }
    Do you have an idea ?

    [EDIT] I found the issue, the cursor had a wrong position but the position calculated was good.
    But I see that the cursor is not always where the player shoot :s
    Last edited by rXp; 02-23-2012 at 11:16 AM.

  5. #5
    MSgt. Shooter Person
    Join Date
    Mar 2011
    Location
    Norway
    Posts
    70

    Default

    Quote Originally Posted by rXp View Post
    But I see that the cursor is not always where the player shoot :s[/B]
    Hm, that's not good

    Is there a big difference between the cursor and the actual aiming?
    Have you noticed any specific incorrect behaviour? For example; 'only when aiming to the left'.
    If it's just a few degrees, it could be that you just have to adjust the aim by the crosshair's textureheight and width.

  6. #6

    Default

    The first was about that (drawtile). But now the more i look down the more it is incorrect (the crosshair gets too low).
    I calcule the angle with an atan2 of the direction vector (the one that is created by (crosshair2DPos-player2DPos) and add or not pi/2 for the right side , what is wrong ?

    rXp>!<

    Sent from my Galaxy SII using tapatalk.

    [EDIT] Here is some screenshots of the issue :
    OK

    A bit off

    Total off
    Last edited by rXp; 02-24-2012 at 06:27 AM.

  7. #7
    MSgt. Shooter Person
    Join Date
    Mar 2011
    Location
    Norway
    Posts
    70

    Default

    Thanks for pointing this out
    It took a while for me to find the problem, but I managed to fix it eventually.

    I don't know whether you still have this problem or not, but if you do; you can check out my new code in the same old thread: http://forums.epicgames.com/threads/...1#post30115814

    To summarize:
    The problem was I was using the player's 2D-projected position to calculate the aim, while I should have been using the weapon-socket.
    If you fix that, the offset should disappear.


 

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
  •  
Copyright ©2009-2011 Epic Games, Inc. All Rights Reserved.
Digital Point modules: Sphinx-based search vBulletin skin by CompletevB.com.