AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   MOVETYPE_BOUNCE without touching anything (https://forums.alliedmods.net/showthread.php?t=187607)

Backstabnoob 06-15-2012 14:44

MOVETYPE_BOUNCE without touching anything
 
How do I simulate MOVETYPE_BOUCE if an entity reaches a set origin (for example 500 < x < 900 and 100 < y < 1500)? I want the entity to 'bounce' and go back in reverse direction. I tried executing Ham_Touch but it didn't do anything.

Exolent[jNr] 06-15-2012 14:51

Re: MOVETYPE_BOUNCE without touching anything
 
Just reflect their velocity as if they bounced.

Backstabnoob 06-15-2012 15:01

Re: MOVETYPE_BOUNCE without touching anything
 
Thanks, works

Backstabnoob 06-15-2012 15:49

Re: MOVETYPE_BOUNCE without touching anything
 
One question: If I reverse the velocity with * -1.0, it goes backwards and doesn't reverse the angle. How would I do that? I was never good with this velocity stuff :oops:

<VeCo> 06-15-2012 16:05

Re: MOVETYPE_BOUNCE without touching anything
 
Quote:

Originally Posted by Backstabnoob (Post 1729398)
One question: If I reverse the velocity with * -1.0, it goes backwards and doesn't reverse the angle. How would I do that? I was never good with this velocity stuff :oops:

Subtract the angles from 180 degrees?

Backstabnoob 06-15-2012 16:21

Re: MOVETYPE_BOUNCE without touching anything
 
More like multiply it by two, but where and how?

Exolent[jNr] 06-15-2012 17:19

Re: MOVETYPE_BOUNCE without touching anything
 
Is it always a certain plane it is reflecting from?

If you know the normal of the plane it is reflecting off of, you can do this:
Code:
new Float:velocity[3], Float:normal[3]; new Float:reflected[3]; xs_vec_reflect(velocity, normal, reflected); // set velocity to reflected

Backstabnoob 06-15-2012 20:25

Re: MOVETYPE_BOUNCE without touching anything
 
I'm trying to make a sort of virtual wall that's passable by the players but impassable by the entity (soccerjam ball). If the entity touches the origin, it should get reflected.

The box is defined like this:
if( !(1808.0 < Y < 2670.0 ) || !( -2717.0 < X < -1744.0 ) || Z > 100.0 )
// reflect the ball

I tried something with the example you posted but I've been only half successful. It gets reflected only when it wants to and the vector length is somehow twisted (that should be speed if I'm correct) as the ball's speed usually increases when it touches the fake wall.

Here's the code in the ball's think:

Code:
entity_set_float( iEntity, EV_FL_nextthink, halflife_time( ) + 0.05 )         static Float:vOrigin[ 3 ], Float:vBallVelocity[ 3 ]     entity_get_vector( iEntity, EV_VEC_origin, vOrigin )     entity_get_vector( iEntity, EV_VEC_velocity, vBallVelocity )         static iOwner; iOwner = pev( iEntity, pev_iuser1 )     static iSolid; iSolid = pev( iEntity, pev_solid )             if( !( 1808.0 < vOrigin[ 1 ]/*2344*/ < 2670.0 ) || !( -2717.0 < vOrigin[ 0 ]/*2239*/ < -1744.0 ) || vOrigin[ 2 ] > 100.0 )     {         new Float: normal[ 3 ], Float: reflected[ 3 ]                 /* I wanted to decrease the speed here but it doesn't work, it works on Ham_Touch though */         new Float: to_change[ 3 ]         to_change[ 0 ] = vBallVelocity[ 0 ] * 0.85         to_change[ 1 ] = vBallVelocity[ 1 ] * 0.85         to_change[ 2 ] = vBallVelocity[ 2 ] * 0.85                 xs_vec_normalize( vOrigin, normal )                 xs_vec_reflect( to_change, normal, reflected )                     entity_set_vector( iEntity, EV_VEC_velocity, reflected )     }

I'm pretty sure I did a huge mistake somewhere. Please correct me if that's the case as I really don't have a clue on what I'm doing. Vector stuff was never friends with me -.-

Exolent[jNr] 06-15-2012 21:03

Re: MOVETYPE_BOUNCE without touching anything
 
Code:
xs_vec_normalize( vOrigin, normal )

That's not what I meant by a normal. The normal describes the direction a plane's flat side is facing.

How do you want this to bounce? Backwards at where it came from, or as if it hit a wall at an angle?

Backstabnoob 06-16-2012 04:54

Re: MOVETYPE_BOUNCE without touching anything
 
Exactly as if it would hit a wall (with an angle). Also, do you have an idea on why the speed is getting increased on bounce? Sometimes it just bounces between two planes until it gets stuck and it looks super retarded.


All times are GMT -4. The time now is 06:08.

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