Slow and fast motion in physic

Slow and fast motion in physic
0.0 0

#1

Hi,
how can I implement slow and fast motion in physics in cc 1.5?
Thanks.


#2

Any Idea???


#3

What do you mean?


#4

I think the question is clear!!!
for example : I have an object that falling in a gravity field so I want to slow down falling object after some dt from starting .
I DON’T want to reduce gravity values to do this.


#5

The physics in Creator uses Box2d.

I hope this link would help:

http://www.box2d.org/forum/viewtopic.php?t=7345


#6

Thanks I read this before but did’t help!!
Also I test cc.director.getPhysicsManager()._world.Step(a,b,c) but did’t work.


#7

There is something like world->setspeed(float)
And i dont know if u can, but maybe you could turn off the autostep and call the world step by yourself with any delta time u want


#8

There is’t such thing in cc.


#9

How about using the gravity scale property?


#10

don’t worry
For controlling speed of Physics see:
https://github.com/cocos-creator/creator-docs/blob/master/source/en/scripting/actions.md
under the tab Container Action — 5 section.
use that idea.


#11

What???
cc.speed is for controlling speed of an action it is not for physic speed!!!


#12

yes but you can use it to slow down your falling object. if you don’t know how to do that. i will explain with example.


#13

I don’t know how to use it, please explain .


#14

ok i will explain but let me know that you want:
that the speed of the falling object (which have fast speed ) decrease speed gradually while coming to ground, e.g first it have speed of 2s and after some dt it change to 1.5s and 1s… ???
OR
that the speed of the falling object remains constant from top to ground, e.g 1s ( slow speed).???
are you getting me?
i will answer according to your reply


#15

@Salman Using box2d elements and manipulating their movement/ behavior using cocos animation module is pretty bad idea. It will cause problems with collision resolution and affect objects in unexpected way.

@hossainiir try cc.director.getPhysicsManager().gravity = cc.v2(x,y); by changing gavity scale at appropriate time you can achieve slow motion on falling elements.


#16

@Lazy_Gamer, @hossainiir do not want to change gravity, using Action is his only option i know for him.


#17

Thanks my friends ,but I think there should be a better way, for example a parameter that change dt in physics update!!!


#18

In cocos creator v1.5.1:
write this code in
onload:function(){
var action = cc.speed(
cc.spawn(
cc.moveBy(speed_of_object, x, y)
), 0.5);
this.node.runAction(action);
}
1Step: now in place of speed_of_object you can write any value i-e 0.1, 0.2 or 1 or 2 etc
Note: 0.1 is fast and 1 is slow and 10 is slowest value and so on.
2Step: in place of x write value of x. i-e 0 or any value.
3Step: in place of y write value of y. i-e -500 or any value where at which height you want to spawn it.
and then add this code to one of the node and try it out.


#19

I solved the problem by overriding default update of PhysicsManager ,this is the code :

physicsManager = cc.director.getPhysicsManager()
physicsManager.speed = 4
physicsManager.update=()->
	world = physicsManager._world
	if (!world || !physicsManager.enabled) then return
	physicsManager.emit('before-step')
	physicsManager._steping = true
	timeStep = physicsManager.speed/cc.game.config['frameRate']
	world.Step(timeStep, 10, 10);
	world.DrawDebugData();
	physicsManager._steping = false;
	events = physicsManager._delayEvents;
	for i in [0..events.length]
		event = events[i]
		if event
			event.target[event.func].apply(event.target, event.args);
	events.length = 0;
	physicsManager._syncNode();

by changing the physicsManager.speed value you can have fast or slow motion


#20

How do you let physicsManager.update() to run? I see it get called in in browser but not in simulator.