I have been looking around recently for a way of making a laser type object but it seems that the forums had nothing much to offer.
I decided to look into how I would make a single object laser which would stay locked on to an object as I where moving around it and by chance managed to come up with this code:
(Note that I am so generous, I even made a simple manually aimed laser for anyone thats needs this.)
Hide mouse
Make object cube 1, 5
Position object 1, 10,10,10
Make object cube 2, 5
Position object 2, 53,10,42
Make object Sphere 3, 3
Position Object 3, 10,10,10
Color object 3, RGB(255,255,0)
Load object "laser.x", 4
Position object 4,10,10,10
Color object 4, RGB(255,0,0)
Scale object 4, 100,100, __Distance(1,2) * 50
Point object 4, Object Position X(2), Object Position Y(2), Object Position Z(2)
Position camera 15,125,15
Rotate camera 90,0,0
Do
_UpdateCrosshair()
_MoveObject(2)
Select MouseClick()
Case 1
_AutoFireLaser(1,2)
EndCase
Case 2
_ManualFireLaser(1)
EndCase
Case Default
Hide Object 4
EndCase
EndSelect
_ShowText()
loop
Function _UpdateCrosshair()
Move Object Left 3, -MouseMoveX() / 3.0
Move Object 3, -MouseMoveY() / 3.0
EndFunction
function _MoveObject(ObjectID as Integer)
Move Object ObjectID, 0.7
Turn Object left ObjectID, 1
EndFunction
Function _AutoFireLaser(Attacker As Integer, Target As Integer)
Show object 4
Scale object 4, 100,100, (__Distance(Attacker, Target) * (100 / Object Size Z(4)))
Position Object 4, Object Position X(Attacker), Object Position Y(Attacker), Object Position Z(Attacker)
Point object 4, Object Position X(Target), Object Position Y(Target), Object Position Z(Target)
EndFunction
Function _ManualFireLaser(Attacker As Integer)
Show object 4
Scale object 4, 100,100, (__Distance(Attacker, 3) * (100 / Object Size Z(4)))
Position Object 4, Object Position X(Attacker), Object Position Y(Attacker), Object Position Z(Attacker)
Point object 4, Object Position X(3), Object Position Y(3), Object Position Z(3)
EndFunction
Function __Distance(Object1 As Integer, Object2 As Integer)
xd = OBJECT POSITION X(Object1) - OBJECT POSITION X(Object2)
yd = OBJECT POSITION Y(Object1) - OBJECT POSITION Y(Object2)
zd = OBJECT POSITION Z(Object1) - OBJECT POSITION Z(Object2)
Distance# = Sqrt( xd^2 + yd^2 + zd^2 )
ENDFUNCTION Distance#
Function _ShowText()
Text 0,0, "Left mouse button for an auto aimed laser"
Text 0,10, "Right mouse button for a manually aimed laser"
EndFunction
The attached object is a big part of this laser. If you attempt to use this code with just a box, you will have to adjust it to move the box to the middle of the two objects. My attached box however does not have the center of the object as the center so that I can tell it to start in one spot and stay there during scaling.
I can't find the way to add this to the codebase, I guess its because my account is on nooby mode. If anyone could, please stick it in there! Thanks!
Edit:
If there is a way to change the title, I can't find it. But this is for DBPro.