Snowball Gravity

Blitz3D Forums/Blitz3D Beginners Area/Snowball Gravity

Happy Llama(Posted 2012) [#1]
I want to add gravity to the snowballs. I have made a Field gravity and decrease it by 0.001 in a For Next loop. When I try to move the snowball by gravity, it won't go down. Any suggestions on how to fix this? Thanks.

Happy Llama



Last edited 2012


Yasha(Posted 2012) [#2]
Firstly, you're not using the "yspeed" field for anything. You use a local in the main loop that's also called "yspeed" - is this intentional? The only thing you do to the field of the same name in the main loop is zero it (since you zero it directly above the line manipulating the local... if that was supposed to be the field, it wouldn't do anything anyway). It's not entirely clear what your intention is in this part of the code.

Secondly, both the local and the field are defaulting to integers, not floats, and therefore trying to modify them by 0.01 (note: not 0.001 in the actual code) will round to zero and have no effect.

Line 138 by the way highlights a bug in Blitz3D: it should really complain that you've used the float sigil on an integer field, but for some reason doesn't (sigils don't do anything after the line where the variable was declared - best avoid them except in declarations). The presence of the float sigil here is therefore not changing the fact that that field holds an integer.

(I should take a moment to recommend the editor IDEal, which helpfully highlighted all of these errors in red for me!)


Matty(Posted 2012) [#3]
Changed as follows:

For s.snowball = Each snowball	
	MoveEntity s\mesh,0,s\yspeed,1 ;LINE MODIFIED - s\yspeed used instead of yspeed
	;NEW LINE HERE ADDED BY MATTY
	s\yspeed = s\yspeed - gravity
	If Abs(EntityZ(s\mesh)) > 400 	
	    FreeEntity s\mesh			
	    Delete s					
	End If
Next


Note I haven't read the rest of your code so no idea if the rest works as you want it to but hopefully that should put you on the right track...

Last edited 2012


Happy Llama(Posted 2012) [#4]
thanks