how to make enemy go FLYING on the y and z axis?

Blitz3D Forums/Blitz3D Beginners Area/how to make enemy go FLYING on the y and z axis?

Guy Fawkes(Posted 2010) [#1]
How would I make an enemy go FLYING on the y and z axis until he runs into a wall, at which case entitycollided will ensure that he blows up?

what would be the formula for this used with moveentity?


_PJ_(Posted 2010) [#2]
What?

Define what you mean by "go flying"

You can use TranslateEntity to move an entity in absolute global directions. Call this every loop for continuous movement.

The collision can be handled by Blitz Collisions with a "Stop" response.


Guy Fawkes(Posted 2010) [#3]
I mean when my player is within the distance of say 20, and is in home attack mode, the enemy's y-gravity, and when he's in the air, change the value of the z axis so it looks like when he's flying, he comes down in an arch. the enemy will rise making it LOOK like my player just knocked the enemy into the sky. and he slowly falls down due to gravity on the y axis, and velocity on the z axis til he hits the ground


_PJ_(Posted 2010) [#4]
I am having a lot of difficulty trying to understand your post, it seems like random phrases concatenated together with commas and full-stops.

If you had implemented some form of physics into your game, you could have just applied the details to the enemy object as a physics object, however, it appears that you havent, so continuing with a pseudo-physics suggestion, did you mean something like this?

Graphics3D 1024,768,32,6

AmbientLight 128,128,128

Global Cam=CreateCamera()
Global En=CreateCone(8)
EntityColor En,64,260,32

Global Sun=CreateLight()
PositionEntity Sun,-10,20,0
PointEntity Sun,En

Global Ground=CreatePlane()

T=CreateTexture(128,128)
SetBuffer TextureBuffer(T)
ClsColor 128,128,128
Cls
Color 160,160,160
Rect 0,0,64,64,True
Rect 64,64,64,64,True
SetBuffer BackBuffer()
EntityTexture Ground,T
FreeTexture T

MoveEntity Cam,0,0,-10
MoveEntity En,0,2,0
MoveEntity Ground,0,-1,0

PointEntity Cam,En

Global Clicked
Global Gravity=0-9.8
Global Velocity
Global AirResistance=5

While Not KeyDown(1)
	If (Clicked)
		TurnEntity En,-2,0,0
		TranslateEntity En,0,Gravity,0
		MoveEntity En,0,0,Velocity
		If (Velocity)
			Velocity=Velocity-AirResistance
			If (Velocity) Then Velocity=0
		End If
	Else
		If MouseHit(1) 
			RotateEntity En,-45,0,0
			Velocity=50
			Clicked=True
		EndIf
	End If
	UpdateWorld
	RenderWorld
	Flip
Wend
EndGraphics
End




Guy Fawkes(Posted 2010) [#5]
something like this:



It's the EXACT same physics for when u kick a football


_PJ_(Posted 2010) [#6]
Yes, that's what my code implies.

The only accelerations are gravity and air resistance

Air Resistance will always affect motion against the current direction and gravity will act 'downwards'.

At the moment of 'impact', you can give the object an initial velocity.

The equation

s = ut + ½ at²

may be useful as it gives the linear displacement (s) after time (t).
The acceleration, (a) is Gravity+Air Resistance, however you will need to ensure that the acceleration is calculated accordingly

Gravity=Sin(a)
Air Resistance=Cos(a)

Each loop can be interpreted as time (t)+1, giving an arbitrary result for (s)


Guy Fawkes(Posted 2010) [#7]
but how can i use ur s = ut + 1/2 a2^2?

i need to see an example of a football type physics example, in order to learn where im going wrong in my current formula, cuz right now i can get it to fly a LITTLE bit but it stays in the same place, and doesnt come down like a football


Guy Fawkes(Posted 2010) [#8]
gah! still cant figure it out! ><


Guy Fawkes(Posted 2010) [#9]
Ok. How would I make the gravity go back down to 0 GRADUALLY?



Then I think I got it


_PJ_(Posted 2010) [#10]
Graphics3D 1024,768,32,6
AmbientLight 128,128,128

Global Cam=CreateCamera()
Global Sun=CreateLight()

PositionEntity Sun,-10,20,0

Global Ball=CreateSphere()

PointEntity Sun,Ball

Global Ground=CreatePlane()

T=CreateTexture(128,128)
SetBuffer TextureBuffer(T)
ClsColor 128,128,128
Cls
Color 160,160,160
Rect 0,0,64,64,True
Rect 64,64,64,64,True
SetBuffer BackBuffer()
EntityTexture Ground,T
FreeTexture T

MoveEntity Cam,0,1,-10
MoveEntity Ground,0,-1,0

PointEntity Cam,Ball

Global BallMass#=0.2
Global Momentum#=0.0
Global BallVelocity#=0.0

Global Power#=2.0
Global KickAngle=45

Global Gravity#=9.8

While Not KeyDown(1)
	If MouseHit(1)
		FlushMouse
		Kick(Power)
	End If
	
	MoveEntity Ball,0,0,BallVelocity*Abs(Cos(EntityPitch(Ball,True)))
	TranslateEntity Ball,0,0-(Gravity*BallMass*Abs(Sin(EntityPitch(Ball,True)))),0,True
	If (EntityY(Ball,True)<(EntityY(Ground,True)+1))
		PositionEntity Ball,EntityX(Ball,True),EntityY(Ground,True)+1,EntityZ(Ball,True),True
		Bounce()
	Else
		TurnEntity Ball,1,0,0,True
	End If
	
	UpdateWorld
	RenderWorld
	Flip
Wend

Function Kick(Power)
	Momentum=Power
	BallVelocity=Momentum/BallMass
	RotateEntity Ball,0-KickAngle,0,0,True
End Function

Function Bounce()
	Momentum=Momentum-Momentum/2.0
	If (Momentum<0) Then Momentum=0
	BallVelocity=Momentum/BallMass
	If (BallVelocity<0) Then BallVelocity=0	
	If ((Momentum>0) And (BallVelocity>0)) Then Kick(Momentum)
End Function



_PJ_(Posted 2010) [#11]
Sorry posted brefore I read your last post.

Gravity shouldn't change (asid from minute fluctuations which are essentially negligible for games purposes)

Ideally, you should use a constant for graviuty as it will remain the same throughout your game.

The acceleration due to gravity is therefore also a constant.
What cxhanges os the Velocity due to constant acceleration. Speed downwards increases at the rate of approximately 10 metres per second per second.


Guy Fawkes(Posted 2010) [#12]
Problem. When my player touches the ball, the player no matter at what rotation or position he is, if his entity distance is within 2 feet of the ball, it should activate kick() and the ball should go in the direction the player is pointing.

Problem is, I can only kick it at ONE angle..




Guy Fawkes(Posted 2010) [#13]
still cant get it to work ><


_PJ_(Posted 2010) [#14]

Problem is, I can only kick it at ONE angle..



What's preventing you from altering the angles?
You can change KickAngle to make it more acute for closer to the ground, or obtuse for a high 'lob', whilst the player's global EntityYaw value can be placed in for the ball's initial Yaw.
Function Kick(Power)
	Momentum=Power
	BallVelocity=Momentum/BallMass
	RotateEntity Ball,0-KickAngle,EntityYaw(PLAYERENTITY,True),0,True
End Function



Guy Fawkes(Posted 2010) [#15]
so rotateentity Ball,0-KickAngle,EntityYaw(PLAYERENTITY,True),0-KickAngle?

i dont get it


_PJ_(Posted 2010) [#16]
Why would you want 0-KickAngle as a Roll parameter?
The KickAngle vartiable is just used for the elevation.


Who was John Galt?(Posted 2010) [#17]
You will never be a programmer, Rez. You always want the answer handed to you on a plate, which means you will never learn a thing.


Guy Fawkes(Posted 2010) [#18]
still dont get it. ignoring john galt and anyone elses snide comments.


Nate the Great(Posted 2010) [#19]
well for realistic gravity you need a variable for y velocity

every frame subtract a certain amount from this velocity and if it collides with soemthing set the velocity to 0. If the player jumps set the velocity to a positive number. That way your player will fall in a parabola :)


_PJ_(Posted 2010) [#20]
Everything you need is done, Rez... what's the problem?

How can you expect to program physics into a game if you clearly have no understanding of Physics?

Read up on classical (Newtonian) mechanics. Compare what is written in textbooks to the maths given in my example.
I have simplified the code to ensure factors such as air resistance and the spin of the ball is negligible.


Guy Fawkes(Posted 2010) [#21]
um, the fact that u cant kick the ball with ur player from any angle.


Serpent(Posted 2010) [#22]
What angle do you want to change? The pitch (up/down) or the yaw (left/right)? At the moment your variable KickAngle is initially set to 45 degrees and left at that - it is not changed anywhere else. If you want to change the pitch according to, say, how close the player is to the ball you actually need to change this variable believe it or not. Also, no matter what you are setting the direction of the ball (it's yaw) to 0. You cannot kick the ball in more than one direction because your code will ALWAYS specifiy 45 degrees height, 0 degrees direction.

^^^^^^^^^^^^^This was from your last codebox post, didn't realise you had a slightly updated post:
rotateentity Ball,0-KickAngle,EntityYaw(PLAYERENTITY,True),0-KickAngle

Do you understand what Pitch, Yaw and Roll are? Pitch is the height of the entity (up/down). You can think of Yaw is the rotation or direction of the entity (left/right). Roll is the turning of the entity itself - imagine turning an object around the z-axis.
This latest post is closer to what you need - KickAngle (which I would allow to user to change by moving closer or further away from the ball or 'charging up' or something) specifies how high the ball is sent (up/down direction). Then you have specified the Yaw (left/right) to be the player's Yaw - which is alright I guess although you could do change this in better ways. Then you have set the Roll to -KickAngle. This is just a waste of code that will turn the ball on the spot, look very weird, and have no effect on the ball's movement.

So in this bit of code, you try to set the direction of the ball based on it's rotation. Then in the main loop you call this
MoveEntity Ball,0,0,BallVelocity*Abs(Cos(EntityPitch(Ball,True)))

with unneccessarily complicated functions to get around the rotation of the ball. You have effectively wasted all of this effort to get around a useless piece of code involving rotating the ball. In your main code, the rotation of the ball means nothing, therefore your code setting the rotation will not set the direction and only makes the rest of your code more complicated.

Do you understand the basics of physics? If you do not have a clue about where to start, then you shouldn't be attempting something like this but building up to it. Do you understand Newton's laws and the idea of acceleration? For physics code like this, you should have the ball's velocity stored and each frame modify it according to the forces acting on it (e.g. scale down speed to simulate air resistance, subtract the constant for gravity from the Y speed to simulate gravity).


_PJ_(Posted 2010) [#23]

um, the fact that u cant kick the ball with ur player from any angle.



I already told you...

What's preventing you from altering the angles?
You can change KickAngle to make it more acute for closer to the ground, or obtuse for a high 'lob', whilst the player's global EntityYaw value can be placed in for the ball's initial Yaw.

Function Kick(Power)
Momentum=Power
BallVelocity=Momentum/BallMass
RotateEntity Ball,0-KickAngle,EntityYaw(PLAYERENTITY,True),0,True
End Function




@Serpent - I omitted air resistance for simplicity. The ball loses momentum through its loss of kinetic energy when it bounces.


Ross C(Posted 2010) [#24]

Do you understand the basics of physics?



Of course he does. He wouldn't be trying this if he didn't ;)


Serpent(Posted 2010) [#25]
Ross - I know what your saying but it was posts like this that alarmed me:
How would I make the gravity go back down to 0 GRADUALLY?


Malice - makes sense not to include air resistance. I won't bother posting anything more here anyway - my knowledge of physics is very limited.


Ross C(Posted 2010) [#26]
I was being sarcastic :)