collisions and moving

Blitz3D Forums/Blitz3D Beginners Area/collisions and moving

olo(Posted 2008) [#1]
Hi all, i have encountered some problems while creating a program. Here is an explanation of what i want to achieve:

-i will have a cube with some cones around
-then i will be able to move the cube
-when the cube gets close to a cone the cone moves away from the cube

Ok, so the problem is that i do not know how to do the last point; I dont know how to make the cones move away from the cube when the cube is near.

all suggestions/advice welcome
thanks :D


Santiworld(Posted 2008) [#2]
i think is something like this... but i not shure

cube = createcube()
entitytype cube,a
entityradius cube,2 <= the range to sphere collision for your cube

cone = createcone?() :)
entitytype cone,b

collisions a,b,2,3



the cube must use a sphere collision...
becouse, i don't know... :)


olo(Posted 2008) [#3]
thank you for your reply..i was waiting anxiously for someone to help. However, that doesnt realy answer my problem :(

i know the collision stuff i just have problems with the moving cones.

here is the code... ( i would like to be able to make a collision that when th cube touches a cone, the cone moves away a few spaces...then stops)

Graphics3D 640,480

SetBuffer BackBuffer()

cam=CreateCamera()

light=CreateLight()

;SeedRnd MilliSecs()

;collisions
type_hole=1
type_cone=2
type_player=3

;background
bg=CreateCube()
PositionEntity bg,0,0,5
ScaleEntity bg, 10,10,1


;hole
hole=CreateSphere(100)
PositionEntity hole, -3,0,4
ScaleEntity hole, 0.4,0.4,0.4
EntityColor hole, 0,0,0
EntityType hole, type_hole

;cones
Dim cone(5)
For s=0 To 5
cone(s)=CreateCone()
ScaleEntity cone(s), 0.2,0.2,0.2
EntityColor cone(s), 0,0,255
PositionEntity cone(s), Rand(-2.5,4), Rand(-2.5,4),4
EntityType cone(s), type_cone
Next

;player(cube)
cube=CreateCube()
PositionEntity cube, 3,1,4
ScaleEntity cube, 0.1,0.3,0.2
EntityColor cube,255,0,0
EntityType cube, type_player
EntityRadius cube, 0.2

;collisions
Collisions type_player, type_cone,3,1
Collisions type_cone, type_player, 3,1

;prog. run
While Not KeyDown(1)

If KeyDown(200) Then MoveEntity cube,0,0.02,0
If KeyDown(208) Then MoveEntity cube, 0,-0.02,0
If KeyDown(205) Then MoveEntity cube, 0.02,0,0
If KeyDown(203) Then MoveEntity cube, -0.02,0,0


RenderWorld
UpdateWorld

Flip

Wend

End


i think it has something to do with entitycollided but i really dont know what...

Please help...anyone


puki(Posted 2008) [#4]
when the cube gets close to a cone the cone moves away from the cube

You can do this by checking the EntityDistance of the cube against each cone - when the distance is under a certain amount, you move the cone for however long you want. You can use EntityDistance again to make a cone stop moving once it is a certain distance from the cube.


olo(Posted 2008) [#5]
ok, thanks but i have never used entitydistance before, can you please explain.


Warner(Posted 2008) [#6]
To elaborate on puki's suggestion, here is an example:
For s=0 To 5
ent = cone(s)

	dd# = EntityDistance(cube, ent)
	If dd <> 0 Then force# = 0.01 / dd Else force# = 0
	If force > 0.015 Then
		PointEntity ent, cube
		MoveEntity ent, 0, 0, -force
		RotateEntity ent, 0, 0, 0
	End If
		
Next

In the code archives, there is also an entry that is called 'push a row of cubes', that might be helpful.


olo(Posted 2008) [#7]
Eureka! thank you so much, everyone that posted. I now have it running just like i wanted, thank so much.

:D