Stona Persona Posted February 15, 2023 Share Posted February 15, 2023 Greetings fellas, im currently trying to figure out how to build a player system like in the PS1 era survival horror games like Resident Evil for example. So far i got static cameras to switch, tank controls and a very basic shooting mechanic (hold down R mouse and press L mouse to shoot). But now im kinda stuck at how to approach a system that lets my player lock onto an enemy when aiming. Some help with pseudo code would be much appreciated. Would i try to get distances between player and the closest enemy entity or would i use a pick with maybe a bigger radius so you kinda have to roughly aim into the enemies direction and if pick hits the player is locked on? Im still trying to figure the code stuff out, so not a pro coder here. Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted February 15, 2023 Share Posted February 15, 2023 I think the pick idea would work better. Like you say, you would have to roughly aim at the enemy first. Are you using C++ or LUA? I haven't used Leadwerks in ages and right now I'm pressed for time, but here's the general idea (syntax is off, I'm using the tippy top of my head) Something like this perhaps... there would be more to it than this. float radius = 0.25f; PickInfo pick_info; Vec3 player_pos = player->GetPosition(true); Vec3 target_position = camera->UnProject(screen_centre);//or Project?? I forget if(Pick(player_pos, target_pos, pick_info, radius) == true){ if(pick_info.entity == enemy) { Vec3 enemy_pos = pick_info.entity->GetPosition(true); player->Point(enemy_pos + an_offset_maybe) } } You could use distance as well and get the angle to each enemy to figure out the closest in distance and angle... 1 Quote Link to comment Share on other sites More sharing options...
Stona Persona Posted February 15, 2023 Author Share Posted February 15, 2023 59 minutes ago, SpiderPig said: I think the pick idea would work better. Like you say, you would have to roughly aim at the enemy first. Are you using C++ or LUA? I haven't used Leadwerks in ages and right now I'm pressed for time, but here's the general idea (syntax is off, I'm using the tippy top of my head) Something like this perhaps... there would be more to it than this. float radius = 0.25f; PickInfo pick_info; Vec3 player_pos = player->GetPosition(true); Vec3 target_position = camera->UnProject(screen_centre);//or Project?? I forget if(Pick(player_pos, target_pos, pick_info, radius) == true){ if(pick_info.entity == enemy) { Vec3 enemy_pos = pick_info.entity->GetPosition(true); player->Point(enemy_pos + an_offset_maybe) } } You could use distance as well and get the angle to each enemy to figure out the closest in distance and angle... Thanks for the quick answer, i think i try it out like this. Im using LUA btw, should ve mentioned in first post. Since i use the player to cast a ray out in the world to detect stuff, so i dont plan to use a crosshair i think i wont need the Camera:UnProject but just get the position of the enemy from the pick. The thing is im trying to figure stuff out for so long now i kinda got tired of trying stuff that doesnt work out in the end, so im very thankful for your information. I think ill try to use the pick i already have when aiming and shooting to make it lock onto the picked enemy. 1 Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted February 16, 2023 Share Posted February 16, 2023 That's okay. If you need any further help just post some code and I can take a look for you. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.