Grenade: Difference between revisions
No edit summary |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
Created by Мужик с Чашкой | |||
Do you want to make some kind of grenades in your game? I've got you here pal! | |||
Put these lines of code into your loop_script: | Put these lines of code into your loop_script: | ||
<pre> | <pre> | ||
//BOMB THROWING LOGIC | //BOMB THROWING LOGIC | ||
player check rotation rotx roty | player check rotation rotx roty | ||
degtorad=$roty | degtorad=$roty | ||
degtorad-=45 | degtorad-=45 | ||
degtorad*=0.034906585 | degtorad*=0.034906585 | ||
global.bombthrowy=SIN($degtorad) | global.bombthrowy=SIN($degtorad) | ||
global.bombthrowx=COS($degtorad) | global.bombthrowx=COS($degtorad) | ||
global.bombthrowx*=-15 | global.bombthrowx*=-15 | ||
global.bombthrowy*=-15 | global.bombthrowy*=-15 | ||
degtorad=$roty | degtorad=$roty | ||
degtorad*=0.0174532925 | degtorad*=0.0174532925 | ||
fixbty=SIN($degtorad) | fixbty=SIN($degtorad) | ||
global.bombthrowy+=$fixbty | global.bombthrowy+=$fixbty | ||
degtorad=$rotx | degtorad=$rotx | ||
degtorad*=0.0174532925 | degtorad*=0.0174532925 | ||
global.bombthrowf=SIN($degtorad) | global.bombthrowf=SIN($degtorad) | ||
global.bombthrowf*=350 | global.bombthrowf*=350 | ||
global.bombthrowv=COS($degtorad) | global.bombthrowv=COS($degtorad) | ||
global.bombthrowv*=-350 | global.bombthrowv*=-350 | ||
global.bombthrowv+=80 | global.bombthrowv+=80 | ||
global.bombthrowz=COS($degtorad) | global.bombthrowz=COS($degtorad) | ||
global.bombthrowz*=-21 | global.bombthrowz*=-21 | ||
global.bombthrowz+=21 | global.bombthrowz+=21 | ||
</pre> | |||
21 = player height divided by 2. | 21 = player height divided by 2. | ||
15 = player radius minus one plus grenade radius (works best when it's zero). | 15 = player radius minus one plus grenade radius (works best when it's zero). | ||
350 = throw force. | 350 = throw force. | ||
Use this frame into FSM: | Use this frame into FSM: |
Latest revision as of 12:48, 14 December 2024
Created by Мужик с Чашкой
Do you want to make some kind of grenades in your game? I've got you here pal!
Put these lines of code into your loop_script:
//BOMB THROWING LOGIC player check rotation rotx roty degtorad=$roty degtorad-=45 degtorad*=0.034906585 global.bombthrowy=SIN($degtorad) global.bombthrowx=COS($degtorad) global.bombthrowx*=-15 global.bombthrowy*=-15 degtorad=$roty degtorad*=0.0174532925 fixbty=SIN($degtorad) global.bombthrowy+=$fixbty degtorad=$rotx degtorad*=0.0174532925 global.bombthrowf=SIN($degtorad) global.bombthrowf*=350 global.bombthrowv=COS($degtorad) global.bombthrowv*=-350 global.bombthrowv+=80 global.bombthrowz=COS($degtorad) global.bombthrowz*=-21 global.bombthrowz+=21
21 = player height divided by 2. 15 = player radius minus one plus grenade radius (works best when it's zero). 350 = throw force.
Use this frame into FSM:
frame 0 0.01 0 0 0 SPAWN fbombprj $global.bombthrowx,$global.bombthrowz,$global.bombthrowy $global.bombthrowf,$global.bombthrowv
"fbombprj" - is an enemy with zero radius that does nothing and act as a throwable object, since decorations don't have any physics.
Pros: Now you have a means of throwing stuff. It even takes into account if you look up or down.
Cons: To prevent spawning things through walls when you stand next to them, we have to spawn things one unit inside player's radius. It pushes back a little, barely noticeable while in movement. But if you make your projectile radius bigger that zero - pushback is much more noticable. By tweaking the 15 number - you can increase the pushback even more without changing the projectile radius.