My projectile weapons spawn objects/parts that shoot through the air, But if something is in the way, like a box around a part, even if the part has collision off, the projectile changes trajectory and flies off at an angle.
Does anyone know who to stop this from happening, In properties I have collision off but can touch is on so it can do damage to the player. Is there another property im missing, like massless or something? Or is it something I need to change in the script to not change direction
1 Like
It sounds like the issue might be related to the physics engine interpreting collisions even when you have the CanCollide
property set to false
. Here are a few things you can try to resolve this issue:
1. Ensure Collision Filtering:
Make sure you’re using collision groups to filter out collisions between your projectile and certain objects.
2. Check Anchored and Massless Properties:
Ensure that your projectile is not affected by unintended physics interactions by adjusting the Anchored
and Massless
properties.
3. Raycasting:
Consider using raycasting for detecting impacts instead of relying on physical collisions. This allows for more precise control over what your projectile interacts with.
4. Collision Groups:
Use collision groups to filter what objects your projectile can collide with. This can be set up in the Collision Groups editor in Roblox Studio.
Here’s a detailed breakdown of these steps:
Collision Groups
-
Create Collision Groups:
- Go to the Collision Groups editor in Roblox Studio (View > Collision Groups).
- Create a new collision group for your projectiles and another for objects they should ignore.
-
Assign Parts to Collision Groups:
- Assign your projectile to the new collision group.
- Assign other parts to their respective groups.
-
Set Up Collision Rules:
- In the Collision Groups editor, ensure that the projectile group does not collide with the objects it’s supposed to ignore.
Raycasting for Projectile Detection
Using raycasting instead of physical collisions can give you more control over what your projectile interacts with. Here’s a basic example of how you might implement this:
Client Script (LocalScript) for Firing Projectile:
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
local function fireProjectile()
local startPos = player.Character.Head.Position
local mousePos = mouse.Hit.p
local direction = (mousePos - startPos).unit
local distance = 100 -- Change this value based on how far you want the projectile to travel
local ray = Ray.new(startPos, direction * distance)
local hit, position = workspace:FindPartOnRay(ray, player.Character, false, true)
if hit then
-- Handle the hit - apply damage, effects, etc.
print("Hit:", hit.Name)
else
-- No hit, the projectile travels its full distance
print("No hit, projectile travels full distance")
end
end
mouse.Button1Down:Connect(fireProjectile)
Example of Using Collision Groups:
Setting Up Collision Groups
-
Open Collision Groups:
- In Roblox Studio, go to View > Collision Groups.
-
Create Groups:
- Create two new groups, e.g., “Projectiles” and “IgnoreProjectiles”.
-
Assign Groups:
- Assign the parts you want to ignore to “IgnoreProjectiles”.
- Assign your projectile to “Projectiles”.
-
Set Rules:
- Ensure “Projectiles” and “IgnoreProjectiles” are set not to collide with each other.
Applying Collision Groups in Script:
local PhysicsService = game:GetService("PhysicsService")
-- Assign the projectile to the "Projectiles" group
PhysicsService:SetPartCollisionGroup(projectile, "Projectiles")
Key Takeaways:
-
Collision Groups: Utilizing collision groups can help you filter out unwanted collisions.
-
Raycasting: Raycasting can provide a more controlled way to detect hits.
-
Properties: Ensure properties like
Anchored
and Massless
are correctly set to avoid unintended physics interactions.
These methods should help you resolve the issue of your projectile changing trajectory unexpectedly.
ai generated bro??? for real?