Raised This Month: $32 Target: $400
 8% 

Npc jump


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Point
Junior Member
Join Date: Oct 2014
Old 03-31-2020 , 08:26   Npc jump
Reply With Quote #1

Hello!
I'm looking for a way to make the npc jump when there is an obstacle, as shown in the image.
I don't know how can i detect that in an effective way..

If someone can help me with ideas, thanks.


Last edited by Point; 03-31-2020 at 08:26.
Point is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 03-31-2020 , 08:32   Re: Npc jump
Reply With Quote #2

The way i would do it is, detect if player is pressing any movement button (forward, backward, sideways). Check if movement's current speed is 0, if it is, jump.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Xalus
Veteran Member
Join Date: Dec 2009
Location: Belgium
Old 03-31-2020 , 12:10   Re: Npc jump
Reply With Quote #3

I would suggest something like this:

PHP Code:
#include <amxmodx>
#include <engine>
#include <fakemeta>
#include <xs>

#define bot_classname "bot"

new Float:g_client_jumpdelay[33]

public 
plugin_init()
{
    
// Register: Touch
    
register_touch("worldspawn"bot_classname"touch_wall")
    
register_touch("func_brush"bot_classname"touch_wall")
    
register_touch("func_breakable"bot_classname"touch_wall")
}

public 
touch_wall(entityclient)
{
    if(
is_user_alive(client))
    {
        if(
g_client_jumpdelay[client] < get_gametime())
        {
            
g_client_jumpdelay[client] = (get_gametime() + 1.0)

            new 
Float:client_origin[3], Float:client_angle[3]
            
pev(clientpev_originclient_origin)
            
client_origin[2] -= 36.0 // Checking origin from the feet (not sure value is correct)
            
pev(clientpev_v_angleclient_angle)

            
//client_angle[0] = -10.0 // Not sure why exactly I used this in 'Walk Through Walls'

            // Get the origin in front of the player, and see if something is standing between the 2 points
            
new Float:futur_origin[3]
            
origin_infront(client_angleclient_origin17.0futur_origin)

            new 
trace_handle create_tr2()
            
engfunc(EngFunc_TraceLineclient_originfutur_originDONT_IGNORE_MONSTERSclienttrace_handle)
            
get_tr2(trace_handleTR_vecEndPosfutur_origin)

            if(
get_distance_f(client_originfutur_origin) < 17.0)
            {
                
// Going to force a jump
                
client_print(0print_chat"Bot %i - Is forced to jump"client)

                
engfunc(EngFunc_MakeVectorsclient_angle)
                new 
Float:forward_vector[3]
                
get_global_vector(GL_v_forwardforward_vector)

                
client_angle[0] = forward_vector[0] * 200.0
                client_angle
[1] = forward_vector[1] * 200.0
                client_angle
[2] = 220.0

                set_pev
(clientpev_velocityclient_angle)
            }
        }
    }
}

origin_infront(Float:vAngles[3], Float:vecOrigin[3], Float:flDistanceFloat:vecOutput[3]) // By Exolent
{
    static 
Float:vecAngles[3]
    
xs_vec_copy(vAnglesvecAngles)

    
engfunc(EngFunc_MakeVectorsvecAngles)
    
global_get(glb_v_forwardvecAngles)

    
xs_vec_mul_scalar(vecAnglesflDistancevecAngles)

    
xs_vec_add(vecOriginvecAnglesvecOutput)

__________________
Retired.
Xalus is offline
Glaster
Junior Member
Join Date: Jan 2020
Location: Irkutsk, Russia
Old 11-19-2021 , 23:37   Re: Npc jump
Reply With Quote #4

Quote:
Originally Posted by Xalus View Post
I would suggest something like this
This code works not always: with some obstruction types like crates or not high walls it works fine, but NPCs have problems with stairs: they have not problems with first few but last stair is the biggest problem for them. Besides NPCs with this jumping function have problems with bridging the joints between some brushes. (I'm trying to fix this problem now and after/if it'll be done I'll send code here)

Last edited by Glaster; 11-19-2021 at 23:37.
Glaster is offline
AnimalMonster
Senior Member
Join Date: May 2020
Old 11-20-2021 , 13:08   Re: Npc jump
Reply With Quote #5

You can try by using TraceLine to detect if an entity is 'bigger' than a stair is too close to the npc, get it's origin and decrease y.

What i mean by "Detect if an entity is 'bigger' than a stair" is that you decrease that y with idk (you have to figure out a good value to decrese the y since it's about origin and player's size/model's size) and if trace line hits the object means that it is 'bigger' than a stair so you will make the npc jump if that's the case.
AnimalMonster is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 11-20-2021 , 15:23   Re: Npc jump
Reply With Quote #6

Quote:
Originally Posted by Glaster View Post
This code works not always: with some obstruction types like crates or not high walls it works fine, but NPCs have problems with stairs: they have not problems with first few but last stair is the biggest problem for them. Besides NPCs with this jumping function have problems with bridging the joints between some brushes. (I'm trying to fix this problem now and after/if it'll be done I'll send code here)

i guess what is the problem here but can you send an video or photo example of this issue, so we will be sure and fix will be posted earlier ?
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)
JocAnis is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 11-20-2021 , 15:28   Re: Npc jump
Reply With Quote #7

actually avoiding obstacles should be in npc entity think and not in the touch forward


Here's a trick how to make the npc climb up the stairs.

PHP Code:
    // engfunc(EngFunc_WalkMove    /* Target, Yaw Angle, fDistance Trace, MOVETYPE */
    
if(!engfunc(EngFunc_WalkMoveidYawAngle1.0WALKMOVE_NORMAL)) // NPC Can't make 1 unit forward? 
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 11-20-2021 at 16:08.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Glaster
Junior Member
Join Date: Jan 2020
Location: Irkutsk, Russia
Old 11-27-2021 , 08:55   Re: Npc jump
Reply With Quote #8

Quote:
Originally Posted by JocAnis View Post
i guess what is the problem here but can you send an video or photo example of this issue, so we will be sure and fix will be posted earlier ?
Ok, it's here

1)
2)

Last edited by Glaster; 11-27-2021 at 08:56.
Glaster is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 11-27-2021 , 16:05   Re: Npc jump
Reply With Quote #9

I've a better stock are you interested?

Or you rather fix your code ? But you need to post what you've actually done.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 11-27-2021 at 16:08.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Glaster
Junior Member
Join Date: Jan 2020
Location: Irkutsk, Russia
Old 11-29-2021 , 02:37   Re: Npc jump
Reply With Quote #10

Quote:
Originally Posted by Natsheh View Post
I've a better stock are you interested?
Yes I am! I'm very interested!

Last edited by Glaster; 11-30-2021 at 07:10.
Glaster is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:01.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode