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

Keeping entity at a distance


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 08-23-2021 , 13:58   Keeping entity at a distance
Reply With Quote #1

Hello,
I am trying to keep a solid entity at a certain distance from player's view.
For example: At 150 units in front of player and tracking the distance from player to entity.

So far I am setting the entity velocity to keep it at a distance from player's view, but it works only if I move backwards, not forwards too.

entity_set_aim() function is called on every think of entity.

Code:
Code:
stock entity_set_aim(ent, player) {     static Float:origin[3], Float:ent_origin[3], Float:angles[3]     pev(player, pev_origin, origin)     pev(ent, pev_origin, ent_origin)          xs_vec_sub(origin, ent_origin, origin)     xs_vec_normalize(origin, origin)     vector_to_angle(origin, angles)          angles[0] = 0.0     if(entity_range(ent, player) > ENT_DISTANCE)     {         set_velocity(ent, angles)         angles[1] -= 90.0         set_pev(ent, pev_angles, angles)     } } stock set_velocity(ent, Float:angles[3]) {     static Float: Direction[3]     angle_vector(angles, ANGLEVECTOR_FORWARD, Direction)
    xs_vec_mul_scalar(Direction, float(Speed), Direction) // float(-Speed)
    set_pev(ent, pev_velocity, Direction) }

Edit: Just achieved to move entity forwards and backwards by making the Speed positive and negative. But the entity is not staying in front of player.
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]

Last edited by Shadows Adi; 08-23-2021 at 14:41.
Shadows Adi is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 08-23-2021 , 14:40   Re: Keeping entity at a distance
Reply With Quote #2

https://forums.alliedmods.net/showpo...39&postcount=3

Can you attach some screenshots so we can imagine whats happening?
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 08-23-2021 at 14:43.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 08-23-2021 , 15:07   Re: Keeping entity at a distance
Reply With Quote #3

Here is a short video: https://vimeo.com/591185759

I wanna update the entity's origin within x units from player's front angle in aiming direction.
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]

Last edited by Shadows Adi; 08-23-2021 at 15:09.
Shadows Adi is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 08-23-2021 , 15:18   Re: Keeping entity at a distance
Reply With Quote #4

Quote:
Originally Posted by Shadows Adi View Post
Here is a short video: https://vimeo.com/591185759

I wanna update the entity's origin within x units from player's front angle in aiming direction.
You can use this function shift_entity_position from the link I've posted in the previous post..
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 08-23-2021 , 16:50   Re: Keeping entity at a distance
Reply With Quote #5

It doesn't work, it keeps spinning the entity in a sphere.

Edit: forgot to get view offset. It does work now, thank you!
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]

Last edited by Shadows Adi; 08-23-2021 at 16:55.
Shadows Adi is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 08-23-2021 , 18:07   Re: Keeping entity at a distance
Reply With Quote #6

When using this function, the entity doesn't make solid or touchable while it is in a wall.
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]
Shadows Adi is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 08-24-2021 , 01:00   Re: Keeping entity at a distance
Reply With Quote #7

Quote:
Originally Posted by Shadows Adi View Post
When using this function, the entity doesn't make solid or touchable while it is in a wall.
What do you mean whilst in the wall, explain?

Are you setting the entity maxs and mins?
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 08-24-2021 at 01:01.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 08-24-2021 , 16:31   Re: Keeping entity at a distance
Reply With Quote #8

Quote:
Originally Posted by Natsheh View Post
Are you setting the entity maxs and mins?
Yes

Quote:
Originally Posted by Natsheh View Post
What do you mean whilst in the wall, explain?
I want to allow players to place the entity in walls and keep it's solidity.

Edit: I created the entity using info_target instead of func_wall and now seems to work right.
But, it's origin gets upwards if it touch a wall it seems. Video: https://vimeo.com/591807069

P.S.: I am dropping the entity every frame using EngFunc_DropToFloor right after using shift_entity_position()
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]

Last edited by Shadows Adi; 08-24-2021 at 17:00.
Shadows Adi is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 08-25-2021 , 00:13   Re: Keeping entity at a distance
Reply With Quote #9

Show the code
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 08-25-2021 , 04:21   Re: Keeping entity at a distance
Reply With Quote #10

PHP Code:
RegisterHam(Ham_Think"info_target""ent_ThinkPre")

public 
ent_ThinkPre(iEnt)
{
    if(!
pev_valid(iEnt))
        return

    static 
className[32]
    
pev(iEntpev_classnameclassNamecharsmax(className))

    if(!
equali(classNameg_szClassName)) 
    {
        return
    }

    new 
id pev(iEntpev_owner)

    if(
is_user_alive(id))
    {
        new 
Float:fStartPos[3], Float:fvOFS[3], Float:fAngles[3]
        
pev(idpev_originfStartPos)
        
pev(idpev_view_ofsfvOFS)
        
pev(idpev_anglesfAngles)
        
fAngles[0] = 0.0
        
//fStartPos[2] += fvOFS[2]
        
set_pev(iEntpev_originfStartPos)
        
set_pev(iEntpev_anglesfAngles)
        new 
button get_user_button(id)
        if(
button IN_FORWARD)
        {
            
entity_set_aim(iEntidtrue);
        }
        else
        {
            
entity_set_aim(iEntid);
        }
    } 

    
shift_entity_position(iEnt100.00.030.0)
    
engfunc(EngFunc_DropToFlooriEnt)

    
set_pev(iEntpev_nextthinkget_gametime() + 0.01)
}

stock entity_set_aim(entplayerbool:bBackWards false

    static 
Float:origin[3], Float:ent_origin[3], Float:angles[3
    
pev(playerpev_originorigin)
    
pev(entpev_originent_origin
     
    
xs_vec_sub(originent_originorigin
    
xs_vec_normalize(originorigin
    
vector_to_angle(originangles
     
    
angles[0] = 0.0 
    
if(entity_range(entplayer) > ENT_DISTANCE)
    {
        
set_velocity(entanglesplayerbBackWards)
        
//angles[1] -= 90.0
        
set_pev(entpev_anglesangles)
    }

}

stock set_velocity(entFloat:angles[3], playerbool:bBackWards false)
{
    new 
FloatDirection[3
    
angle_vector(anglesANGLEVECTOR_FORWARDDirection
    
xs_vec_mul_scalar(DirectionbBackWards float(-Speed) : float(Speed), Direction)
    
set_pev(entpev_velocityDirection)
}

stock shift_entity_position(entFloat:forwFloat:rightFloat:up)
{
    new 
Float:vOrigin[3], Float:vAngle[3], Float:vForward[3], Float:vRight[3], Float:vEnd[3];
    
    
pev(entpev_originvOrigin);
    
pev(entpev_anglesvAngle);
    
    
angle_vector(vAngle,ANGLEVECTOR_FORWARDvForward); //or use EngFunc_AngleVectors
    
angle_vector(vAngle,ANGLEVECTOR_RIGHTvRight);
    
    
vEnd[0] = vOrigin[0] + (vForward[0] * forw) + (vRight[0] * right);
    
vEnd[1] = vOrigin[1] + (vForward[1] * forw) + (vRight[1] * right);
    
// Extract up value from vOrigin to make entitystay on ground when in walls but it seems that it didn't work too good
    
vEnd[2] = vOrigin[2] - up;

    
// debug only
    
client_print(0print_chat"origin2: %f"vOrigin[2])

    
// This don't help with anything, so I decided to comment it.
    /*static iTr2; iTr2 = create_tr2();
    engfunc(EngFunc_TraceLine, vOrigin, vEnd, DONT_IGNORE_MONSTERS, ent, iTr2);
    get_tr2(iTr2, TR_vecEndPos, vEnd);
    free_tr2(iTr2);*/

    
set_pev(entpev_originvEnd);

__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]
Shadows Adi 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 21:03.


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