Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Magnitude, Touched or other? [closed]

Asked by
TomsGames 225 Moderation Voter
10 years ago

Alright I'm a bit stuck in the making of my game. If you want to have a look at this game so far here is the link:

http://www.roblox.com/Traffic-Racer-place?id=146148373

Ok so if you've checked out the game you'll notice whilst driving the car if you hit another car nothing happens. This is obviously the next step of my game development and I'm stuck as to how I can do this. The little white squares I have purposefully left visible around the side and front of the cars are what I call 'hitsensors'. Supposedly what happens is when they hit a car they will change a variable causing another script to activate etc... But I just do not know how to make the hitsensor.. sense!

I was told use magnitude, but as you can see that would be very difficult, impractical and time consuming and knowing me it wouldn't work. Currently they have script.Parent.Touched:connect(function) in them but since my cars teleport about and do not gain velocity apparently it is not activating the touched?

How can I do this? Thanks!

P.S The whole game is local.

Locked by JesseSong

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

3 answers

Log in to vote
1
Answered by
nate890 495 Moderation Voter
10 years ago

Interesting problem you are having there. Unfortunately, there really is no way to detect when the car hits another car. Using touched events (if it worked) would be very inefficient and using magnitude would also be inefficient. The best way to go upon doing this, and you're probably not going to like this at all, is to restart using body objects like BodyVelocity and BodyGyro.

For one, your game will run faster by using body objects and the issue you are currently facing will resolve itself, since your cars will automatically apply to Roblox physics. BodyVelocity is to be used to move your vehicle straight and right/left while the BodyGyro is to be used to keep your vehicle straight and inline (that is, if I remember what BodyGyro does correctly- sorry, I'm rusty!)

I also recommend that you take the time to look at the other body objects, mainly BodyPosition.

Hope this helps and good luck with your game.

Ad
Log in to vote
0
Answered by
Muoshuu 580 Moderation Voter
10 years ago

HitSensor.Touched:connect(function(hit) DoStuff() end)

0
Tried that before, does not work :z TomsGames 225 — 10y
Log in to vote
0
Answered by
Vrakos 109
10 years ago

Make sure you put this script where the parts of the car are located.

for Index,Part in pairs(script.Parent:GetChildren()) do
    if Part:IsA("Part") then
        Part.Touched:connect(function(Hit)
                if not Hit.Parent:FindFirstChild("Humanoid") then
                    Part:BreakJoints()
                end
            end
        end)
    end
end