genya10g
|
  |
| Joined: 03 Sep 2008 |
| Total Posts: 1227 |
|
|
| 13 Mar 2013 02:27 PM |
| Suppose I have 2 bricks, Brick A and Brick B, I want Brick A to shoot at Brick B (I know how to do this), but then I want Brick B to be knocked back as it gets shot, how would I do this, lookvector? |
|
|
| Report Abuse |
|
|
genya10g
|
  |
| Joined: 03 Sep 2008 |
| Total Posts: 1227 |
|
| |
|
|
| 13 Mar 2013 02:42 PM |
| Have you tried unanchoring brick B so then when it is hit it will get knocked over? |
|
|
| Report Abuse |
|
|
genya10g
|
  |
| Joined: 03 Sep 2008 |
| Total Posts: 1227 |
|
|
| 13 Mar 2013 02:43 PM |
| I need this to be done with a script for a gun. |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 13 Mar 2013 02:53 PM |
| You can apply same velocity, that bullet is traveling in, to the block it hits. Make sure to check if brick is unanchored, or the block will get slippery, like conveyer. |
|
|
| Report Abuse |
|
|
genya10g
|
  |
| Joined: 03 Sep 2008 |
| Total Posts: 1227 |
|
|
| 13 Mar 2013 02:57 PM |
| By brick I mean player, I have a gun and I`m using a raycast, I want the ray to push the player back a bit on impact. |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 13 Mar 2013 02:59 PM |
Then decide how much velocity to apply to the player's torso. Just experiment how much. Here is how I'd try to do it:
multiplier = 10 torso.Velocity = (gun.Handle-rayHitPosition).unit*multiplier |
|
|
| Report Abuse |
|
|
genya10g
|
  |
| Joined: 03 Sep 2008 |
| Total Posts: 1227 |
|
| |
|
genya10g
|
  |
| Joined: 03 Sep 2008 |
| Total Posts: 1227 |
|
|
| 13 Mar 2013 03:29 PM |
| Didn't work, any other ideas? :3 |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 13 Mar 2013 03:30 PM |
| Try increasing multiplier, by few hundreds? |
|
|
| Report Abuse |
|
|
genya10g
|
  |
| Joined: 03 Sep 2008 |
| Total Posts: 1227 |
|
|
| 13 Mar 2013 03:30 PM |
| It was giving me an error, I`ll show it soon. |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 13 Mar 2013 03:30 PM |
Oh, I hope you spotted my mistake:
torso.Velocity = (gun.Handle.Position-rayHitPosition).unit*multiplier |
|
|
| Report Abuse |
|
|
genya10g
|
  |
| Joined: 03 Sep 2008 |
| Total Posts: 1227 |
|
|
| 13 Mar 2013 03:44 PM |
| Yeah, I already had that :p |
|
|
| Report Abuse |
|
|
genya10g
|
  |
| Joined: 03 Sep 2008 |
| Total Posts: 1227 |
|
|
| 13 Mar 2013 03:49 PM |
Output
Players.Player1.Backpack.Gun.LocalScript:58: bad argument #2 to '?' (Vector3 expected, got nil)
:p |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 13 Mar 2013 03:51 PM |
| Well the ray position will be nil, if it won't hit part. |
|
|
| Report Abuse |
|
|
genya10g
|
  |
| Joined: 03 Sep 2008 |
| Total Posts: 1227 |
|
|
| 13 Mar 2013 03:52 PM |
I already have that checked, then I fixed it so that Hit is actually making sense, still no go:
hit.Parent.Torso.Velocity = Vector3.new(script.Parent.Handle.Position-hit.Position) |
|
|
| Report Abuse |
|
|
velibor
|
  |
| Joined: 24 Nov 2009 |
| Total Posts: 1003 |
|
|
| 13 Mar 2013 03:52 PM |
Be aware that in your RayCasting you also need to cover the fact that you don't hit anything at all.
If that happens that code is useless.
You can better get the Position of the Player torso's and then Knock them back by using that Position. (I would personally use CFraming for this)
|
|
|
| Report Abuse |
|
|
genya10g
|
  |
| Joined: 03 Sep 2008 |
| Total Posts: 1227 |
|
|
| 13 Mar 2013 03:54 PM |
| Guys, I already know how to code, I know that I have to check if nil, I already have. |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 13 Mar 2013 03:54 PM |
hit.Parent.Torso.Velocity = (script.Parent.Handle.Position-hit.Position).unit
You need to use unit, because that's direction and that's how velocity works. Also when you are using unit, remember to multiply it, because it will have small number. |
|
|
| Report Abuse |
|
|
genya10g
|
  |
| Joined: 03 Sep 2008 |
| Total Posts: 1227 |
|
|
| 13 Mar 2013 04:04 PM |
| @zars, I did what you did, but 99% of the time no effect! |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 13 Mar 2013 04:07 PM |
| Hmm well by how much did you multiply? Humanoids usually doesn't like to get pushed around. |
|
|
| Report Abuse |
|
|
genya10g
|
  |
| Joined: 03 Sep 2008 |
| Total Posts: 1227 |
|
|
| 13 Mar 2013 04:08 PM |
for i,v in pairs(hit.Parent:GetChildren()) do if v.className == "Part" then v.Position = v.Position+(hit.Position-script.Parent.Handle.Position).unit*2 end end
I tried just moving his Torso too, and if I use MoveTo() the person can be pushed against a wall then end up being teleported over it. |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 13 Mar 2013 04:09 PM |
| What happens if you multiply with like... 100 or even higher number? |
|
|
| Report Abuse |
|
|
genya10g
|
  |
| Joined: 03 Sep 2008 |
| Total Posts: 1227 |
|
|
| 13 Mar 2013 04:10 PM |
| They get launched, i tried 200, 20, and 2. All of them kill |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 13 Mar 2013 04:12 PM |
| Hmm something like 5? But yeah, humanoids can be annoying.. |
|
|
| Report Abuse |
|
|